summaryrefslogtreecommitdiff
path: root/init/service.cpp
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2022-12-01 15:44:31 -0800
committerDaniel Rosenberg <drosen@google.com>2023-01-10 18:29:46 -0800
commitde76688e40244a45d2396d7d79d7fff2adc03a14 (patch)
tree042b2c563f9dcc98aecfc2c0c0aeb5838ee63deb /init/service.cpp
parentfe9d83251b803190225f936826474f30d9abb307 (diff)
downloadcore-de76688e40244a45d2396d7d79d7fff2adc03a14.tar.gz
init: Add gentle_kill service property
If a service specifies gentle_kill, attempt to stop it will send SIGTERM instead of SIGKILL. After 200ms, it will issue a SIGKILL. Bug: 249043036 Test: atest CtsInitTestCases:init#GentleKill Added in next patch Change-Id: Ieb0e4e24d31780aca1cf291f9d21d49cee181cf2
Diffstat (limited to 'init/service.cpp')
-rw-r--r--init/service.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/init/service.cpp b/init/service.cpp
index b9b33090e..87d9c3a6c 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -26,6 +26,7 @@
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
+#include <thread>
#include <android-base/file.h>
#include <android-base/logging.h>
@@ -887,6 +888,10 @@ void Service::StopOrReset(int how) {
}
if (pid_) {
+ if (flags_ & SVC_GENTLE_KILL) {
+ KillProcessGroup(SIGTERM);
+ if (!process_cgroup_empty()) std::this_thread::sleep_for(200ms);
+ }
KillProcessGroup(SIGKILL);
NotifyStateChange("stopping");
} else {