diff options
author | Ryan Prichard <rprichard@google.com> | 2018-04-11 18:46:38 -0700 |
---|---|---|
committer | Ryan Prichard <rprichard@google.com> | 2018-04-12 14:15:26 -0700 |
commit | 1325ec8cfb85806867b6e88aa2c63f3d183a3353 (patch) | |
tree | 9a5797679ec99b4c125526ac3e05c871f4d6c930 /init/sigchld_handler.cpp | |
parent | af15fbf9aa6bb991a6abe8b2b72acc1a9405eff9 (diff) |
init: use signalfd to catch SIGCHLD
Previously, if init received too many SIGCHLD signals, then the write to
signal_write_fd could fail with EAGAIN. The handler tried to log the
EAGAIN error, and init deadlocked if the interrupted init process had
already acquired a logging-related lock.
Bug: b/77867680
Test: manual
Change-Id: Ief0b5e94d8517827a5a7d03773391ba3ba9447c4
Diffstat (limited to 'init/sigchld_handler.cpp')
-rw-r--r-- | init/sigchld_handler.cpp | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/init/sigchld_handler.cpp b/init/sigchld_handler.cpp index 072a0fb0b..3ec76df0b 100644 --- a/init/sigchld_handler.cpp +++ b/init/sigchld_handler.cpp @@ -39,9 +39,6 @@ using android::base::make_scope_guard; namespace android { namespace init { -static int signal_write_fd = -1; -static int signal_read_fd = -1; - static bool ReapOneProcess() { siginfo_t siginfo = {}; // This returns a zombie pid or informs us that there are no zombies left to be reaped. @@ -102,46 +99,10 @@ static bool ReapOneProcess() { return true; } -static void handle_signal() { - // Clear outstanding requests. - char buf[32]; - read(signal_read_fd, buf, sizeof(buf)); - - ReapAnyOutstandingChildren(); -} - -static void SIGCHLD_handler(int) { - if (TEMP_FAILURE_RETRY(write(signal_write_fd, "1", 1)) == -1) { - PLOG(ERROR) << "write(signal_write_fd) failed"; - } -} - void ReapAnyOutstandingChildren() { while (ReapOneProcess()) { } } -void sigchld_handler_init() { - // Create a signalling mechanism for SIGCHLD. - int s[2]; - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, s) == -1) { - PLOG(FATAL) << "socketpair failed in sigchld_handler_init"; - } - - signal_write_fd = s[0]; - signal_read_fd = s[1]; - - // Write to signal_write_fd if we catch SIGCHLD. - struct sigaction act; - memset(&act, 0, sizeof(act)); - act.sa_handler = SIGCHLD_handler; - act.sa_flags = SA_NOCLDSTOP; - sigaction(SIGCHLD, &act, 0); - - ReapAnyOutstandingChildren(); - - register_epoll_handler(signal_read_fd, handle_signal); -} - } // namespace init } // namespace android |