diff options
author | Tom Cherry <tomcherry@google.com> | 2018-02-21 10:37:44 -0800 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2018-02-21 16:36:03 -0800 |
commit | 6f2d56d584159f1aece2e50e604d8db61deed383 (patch) | |
tree | 2c64e3cf63b4d8dab129cb3bde929156330f243e | |
parent | 2733708cfb2ed041e0a82593eeaae5b48ca44a66 (diff) | |
download | core-6f2d56d584159f1aece2e50e604d8db61deed383.tar.gz core-6f2d56d584159f1aece2e50e604d8db61deed383.tar.bz2 core-6f2d56d584159f1aece2e50e604d8db61deed383.zip |
init: log control messages along with the process that sent them
It's currently not clear that init stops processes due to being sent a
control message nor who sent that message.
Bug: 73343913
Test: send control messages and see the logs
Change-Id: I9e9eff2001e649814107ea961b3b747a1f6da598
-rw-r--r-- | init/init.cpp | 18 | ||||
-rw-r--r-- | init/init.h | 4 | ||||
-rw-r--r-- | init/property_service.cpp | 2 |
3 files changed, 21 insertions, 3 deletions
diff --git a/init/init.cpp b/init/init.cpp index 7e4eaa8c2..efb9c1db3 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -35,6 +35,7 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/properties.h> +#include <android-base/stringprintf.h> #include <android-base/strings.h> #include <cutils/android_reboot.h> #include <keyutils.h> @@ -63,7 +64,10 @@ using namespace std::string_literals; using android::base::boot_clock; using android::base::GetProperty; +using android::base::ReadFileToString; +using android::base::StringPrintf; using android::base::Timer; +using android::base::Trim; namespace android { namespace init { @@ -246,7 +250,7 @@ static const std::map<std::string, ControlMessageFunction>& get_control_message_ return control_message_functions; } -void handle_control_message(const std::string& msg, const std::string& name) { +void HandleControlMessage(const std::string& msg, const std::string& name, pid_t pid) { const auto& map = get_control_message_map(); const auto it = map.find(msg); @@ -255,6 +259,18 @@ void handle_control_message(const std::string& msg, const std::string& name) { return; } + std::string cmdline_path = StringPrintf("proc/%d/cmdline", pid); + std::string process_cmdline; + if (ReadFileToString(cmdline_path, &process_cmdline)) { + std::replace(process_cmdline.begin(), process_cmdline.end(), '\0', ' '); + process_cmdline = Trim(process_cmdline); + } else { + process_cmdline = "unknown process"; + } + + LOG(INFO) << "Received control message '" << msg << "' for '" << name << "' from pid: " << pid + << " (" << process_cmdline << ")"; + const ControlMessageFunction& function = it->second; if (function.target == ControlTarget::SERVICE) { diff --git a/init/init.h b/init/init.h index ecce5d789..d4a0e963b 100644 --- a/init/init.h +++ b/init/init.h @@ -17,6 +17,8 @@ #ifndef _INIT_INIT_H #define _INIT_INIT_H +#include <sys/types.h> + #include <string> #include <vector> @@ -36,7 +38,7 @@ extern std::vector<std::string> late_import_paths; Parser CreateParser(ActionManager& action_manager, ServiceList& service_list); -void handle_control_message(const std::string& msg, const std::string& arg); +void HandleControlMessage(const std::string& msg, const std::string& arg, pid_t pid); void property_changed(const std::string& name, const std::string& value); diff --git a/init/property_service.cpp b/init/property_service.cpp index ecd5baa1d..0cf61840f 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -436,7 +436,7 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value, return PROP_ERROR_HANDLE_CONTROL_MESSAGE; } - handle_control_message(name.c_str() + 4, value.c_str()); + HandleControlMessage(name.c_str() + 4, value, cr.pid); return PROP_SUCCESS; } |