Merge "init: log control messages along with the process that sent them" am: 0f8a67d6a8
am: 76583e1637
Change-Id: Id60a6e1ecac59f5ed875e0b7ff5f5c289e7e617e
diff --git a/init/init.cpp b/init/init.cpp
index 7e4eaa8..efb9c1d 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 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 @@
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 @@
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 ecce5d7..d4a0e96 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 @@
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 ecd5baa..0cf6184 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -436,7 +436,7 @@
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;
}