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

Commit 8579ef58 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Identify untracked processes" into main

parents e95e024f a129dc90
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/process.h>
#include <android-base/properties.h>
#include <android-base/scopeguard.h>
#include <android-base/strings.h>
@@ -57,6 +58,7 @@
#include <libsnapshot/snapshot.h>
#include <logwrap/logwrap.h>
#include <private/android_filesystem_config.h>
#include <procinfo/process.h>
#include <selinux/selinux.h>

#include "action.h"
@@ -346,7 +348,27 @@ static UmountStat TryUmountPartitions(bool force) {
    return UMOUNT_STAT_ERROR;
}

static void DumpRemainingProcesses() {
    LOG(INFO) << "Remaining userspace processes except init: ";
    android::procinfo::ProcessInfo info;
    std::string error;
    for (const auto& pid : android::base::AllPids{}) {
        if (!android::procinfo::GetProcessInfo(pid, &info, &error)) {
            LOG(WARNING) << "Cannot get info for pid " << pid << ": " << error;
            continue;
        }
        bool init_or_kthread = (info.ppid == 0) || (info.ppid == 2);
        if (init_or_kthread) {
            continue;
        }
        LOG(INFO) << std::format("pid: {} name: ({}) ppid: {} pgrp: {} state: {}", info.pid,
                                 info.name, info.ppid, info.pgrp, static_cast<char>(info.state));
    }
}

static void KillAllProcesses(bool force) {
    // To know what are die-hard processes.
    DumpRemainingProcesses();
    // SIGKILL on force == true. SIGTERM if not.
    WriteStringToFile(force ? "i" : "e", PROC_SYSRQ);
}
+12 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <android-base/logging.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
#include <procinfo/process.h>

#include <thread>

@@ -95,7 +96,17 @@ static pid_t ReapOneProcess() {
                                           exec_duration_ms / 1000.0f);
            }
        } else {
            name = StringPrintf("Untracked pid %d", pid);
            android::procinfo::ProcessInfo info;
            std::string error;
            std::string debug;
            if (android::procinfo::GetProcessInfo(pid, &info, &error)) {
                debug = std::format("pid: {} name: ({}) ppid: {} pgrp: {} state: {}", info.pid,
                                    info.name, info.ppid, info.pgrp, static_cast<char>(info.state));
            } else {
                LOG(ERROR) << error;
                debug = std::to_string(pid);
            }
            name = std::format("Untracked process ({})", debug);
        }
    }