Merge "libprocessgroup: fix boot time performance regression" am: e89ee18b9b

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2467504

Change-Id: Iddcb0c1771b1a247732974dc6c360ce3509e8ee8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Inseob Kim 2023-03-03 17:19:17 +00:00 committed by Automerger Merge Worker
commit 12f447e607

View file

@ -372,6 +372,7 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid,
std::set<pid_t> pgids;
pgids.emplace(initialPid);
std::set<pid_t> pids;
int processes = 0;
std::unique_ptr<FILE, decltype(&fclose)> fd(nullptr, fclose);
@ -390,6 +391,7 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid,
pid_t pid;
bool file_is_empty = true;
while (fscanf(fd.get(), "%d\n", &pid) == 1 && pid >= 0) {
processes++;
file_is_empty = false;
if (pid == 0) {
// Should never happen... but if it does, trying to kill this
@ -419,15 +421,12 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid,
}
}
int processes = 0;
// Kill all process groups.
for (const auto pgid : pgids) {
LOG(VERBOSE) << "Killing process group " << -pgid << " in uid " << uid
<< " as part of process cgroup " << initialPid;
if (kill(-pgid, signal) == 0) {
processes++;
} else if (errno != ESRCH) {
if (kill(-pgid, signal) == -1 && errno != ESRCH) {
PLOG(WARNING) << "kill(" << -pgid << ", " << signal << ") failed";
}
}
@ -437,9 +436,7 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid,
LOG(VERBOSE) << "Killing pid " << pid << " in uid " << uid << " as part of process cgroup "
<< initialPid;
if (kill(pid, signal) == 0) {
processes++;
} else if (errno != ESRCH) {
if (kill(pid, signal) == -1 && errno != ESRCH) {
PLOG(WARNING) << "kill(" << pid << ", " << signal << ") failed";
}
}