summaryrefslogtreecommitdiffstats
path: root/init/init.cpp
diff options
context:
space:
mode:
authoryusukes <yusukes@google.com>2018-02-01 17:14:30 -0800
committeryusukes <yusukes@google.com>2018-02-02 15:28:03 -0800
commit4a4ec14e42e3a395086cfb8d992768a62b33aba4 (patch)
tree7557d02179877f6a7740cf70453cd3e0b189d354 /init/init.cpp
parent0ce76f910b1794d422f8d45d77a3ee2b95ec3d3e (diff)
downloadsystem_core-4a4ec14e42e3a395086cfb8d992768a62b33aba4.tar.gz
system_core-4a4ec14e42e3a395086cfb8d992768a62b33aba4.tar.bz2
system_core-4a4ec14e42e3a395086cfb8d992768a62b33aba4.zip
Do not block SIGTERM in init's child processes
Previously, unless the process unblocks the signal by itself, the signal was never delivered to the process. This caused at least one CTS test failure. Bug: 72453675 Test: 'kill -TERM app_pid' terminates the app process Change-Id: I3977cac75e2673b52c5cf91d34d7a9c258c1a0e4
Diffstat (limited to 'init/init.cpp')
-rw-r--r--init/init.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/init/init.cpp b/init/init.cpp
index 79623c333..bd09e4bcc 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <paths.h>
+#include <pthread.h>
#include <seccomp_policy.h>
#include <signal.h>
#include <stdlib.h>
@@ -491,6 +492,16 @@ static void HandleSigtermSignal() {
HandlePowerctlMessage("shutdown,container");
}
+static void UnblockSigterm() {
+ sigset_t mask;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGTERM);
+
+ if (sigprocmask(SIG_UNBLOCK, &mask, nullptr) == -1) {
+ PLOG(FATAL) << "failed to unblock SIGTERM for PID " << getpid();
+ }
+}
+
static void InstallSigtermHandler() {
sigset_t mask;
sigemptyset(&mask);
@@ -500,6 +511,12 @@ static void InstallSigtermHandler() {
PLOG(FATAL) << "failed to block SIGTERM";
}
+ // Register a handler to unblock SIGTERM in the child processes.
+ const int result = pthread_atfork(nullptr, nullptr, &UnblockSigterm);
+ if (result != 0) {
+ LOG(FATAL) << "Failed to register a fork handler: " << strerror(result);
+ }
+
sigterm_signal_fd = signalfd(-1, &mask, SFD_CLOEXEC);
if (sigterm_signal_fd == -1) {
PLOG(FATAL) << "failed to create signalfd for SIGTERM";