Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f2d56d5 authored by Tom Cherry's avatar Tom Cherry
Browse files

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
parent 2733708c
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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) {
+3 −1
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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;
    }