use process groups for processes started by init
Put every service into a process group, kill the process group
and all child processes created within the group when killing the
service. Removed libutil dependency in libprocessgroup.
Bug: 25355957
Change-Id: Ieed60ec41579f638ab9b1e66a7e6330ed578ab05
Signed-off-by: Collin Mulliner <collinrm@squareup.com>
diff --git a/init/service.cpp b/init/service.cpp
index f5b8b00..4175d05 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -30,6 +30,8 @@
#include <cutils/android_reboot.h>
#include <cutils/sockets.h>
+#include <processgroup/processgroup.h>
+
#include "action.h"
#include "init.h"
#include "init_parser.h"
@@ -97,7 +99,7 @@
if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) {
NOTICE("Service '%s' (pid %d) killing any children in process group\n",
name_.c_str(), pid_);
- kill(-pid_, SIGKILL);
+ killProcessGroup(uid_, pid_, SIGKILL);
}
// Remove any sockets we may have created.
@@ -490,6 +492,7 @@
time_started_ = gettime();
pid_ = pid;
flags_ |= SVC_RUNNING;
+ createProcessGroup(uid_, pid_);
if ((flags_ & SVC_EXEC) != 0) {
INFO("SVC_EXEC pid %d (uid %d gid %d+%zu context %s) started; waiting...\n",
@@ -532,7 +535,7 @@
if (pid_) {
NOTICE("Sending SIGTERM to service '%s' (pid %d)...\n", name_.c_str(),
pid_);
- kill(-pid_, SIGTERM);
+ killProcessGroup(uid_, pid_, SIGTERM);
NotifyStateChange("stopping");
}
}
@@ -583,7 +586,7 @@
if (pid_) {
NOTICE("Service '%s' is being killed...\n", name_.c_str());
- kill(-pid_, SIGKILL);
+ killProcessGroup(uid_, pid_, SIGKILL);
NotifyStateChange("stopping");
} else {
NotifyStateChange("stopped");