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 /init/init.cpp | |
| parent | 2733708cfb2ed041e0a82593eeaae5b48ca44a66 (diff) | |
| download | system_core-6f2d56d584159f1aece2e50e604d8db61deed383.tar.gz system_core-6f2d56d584159f1aece2e50e604d8db61deed383.tar.bz2 system_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
Diffstat (limited to 'init/init.cpp')
| -rw-r--r-- | init/init.cpp | 18 |
1 files changed, 17 insertions, 1 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) { |
