libprocessgroup: Remove max_processes from KillProcessGroup API
The max_processes calculation is incorrect for KillProcessGroup because
the set of processes in cgroup.procs can differ between the multiple
reads in the implementation. Luckily the exact value isn't very
important because it's just logged. Remove max_processes from the API
and remove the warning about the new behavior in Android 11.
Note that we still always LOG(INFO) that any cgroup is being killed.
Bug: 301871933
Change-Id: I8e449f5089d4a48dbc1797b6d979539e87026f43
diff --git a/init/service.cpp b/init/service.cpp
index 5e900ee..2087452 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -194,7 +194,7 @@
}
}
-void Service::KillProcessGroup(int signal, bool report_oneshot) {
+void Service::KillProcessGroup(int signal) {
// If we've already seen a successful result from killProcessGroup*(), then we have removed
// the cgroup already and calling these functions a second time will simply result in an error.
// This is true regardless of which signal was sent.
@@ -202,20 +202,11 @@
if (!process_cgroup_empty_) {
LOG(INFO) << "Sending signal " << signal << " to service '" << name_ << "' (pid " << pid_
<< ") process group...";
- int max_processes = 0;
int r;
if (signal == SIGTERM) {
- r = killProcessGroupOnce(uid(), pid_, signal, &max_processes);
+ r = killProcessGroupOnce(uid(), pid_, signal);
} else {
- r = killProcessGroup(uid(), pid_, signal, &max_processes);
- }
-
- if (report_oneshot && max_processes > 0) {
- LOG(WARNING)
- << "Killed " << max_processes
- << " additional processes from a oneshot process group for service '" << name_
- << "'. This is new behavior, previously child processes would not be killed in "
- "this case.";
+ r = killProcessGroup(uid(), pid_, signal);
}
if (r == 0) process_cgroup_empty_ = true;
@@ -265,7 +256,7 @@
void Service::Reap(const siginfo_t& siginfo) {
if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) {
- KillProcessGroup(SIGKILL, false);
+ KillProcessGroup(SIGKILL);
} else {
// Legacy behavior from ~2007 until Android R: this else branch did not exist and we did not
// kill the process group in this case.
@@ -273,7 +264,7 @@
// The new behavior in Android R is to kill these process groups in all cases. The
// 'true' parameter instructions KillProcessGroup() to report a warning message where it
// detects a difference in behavior has occurred.
- KillProcessGroup(SIGKILL, true);
+ KillProcessGroup(SIGKILL);
}
}