From 12541c61311e0488e9873df754f8328cd12f99b4 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 16 Apr 2010 20:28:11 -0700 Subject: [PATCH] init: reap exited child processes on signal_init If any child processes exit before signal_init, they won't get reaped unless another child process exits after signal_init. Calling handle_signal from signal_init forces them to be reaped immediately. Change-Id: I459cfbfe6cf00f29454c62a8c840baf21cb1fb03 --- init/signal_handler.c | 48 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/init/signal_handler.c b/init/signal_handler.c index b16eef104..e5d308df2 100644 --- a/init/signal_handler.c +++ b/init/signal_handler.c @@ -36,29 +36,6 @@ static void sigchld_handler(int s) write(signal_fd, &s, 1); } -void signal_init(void) -{ - int s[2]; - - struct sigaction act; - - act.sa_handler = sigchld_handler; - act.sa_flags = SA_NOCLDSTOP; - act.sa_mask = 0; - act.sa_restorer = NULL; - sigaction(SIGCHLD, &act, 0); - - /* create a signalling mechanism for the sigchld handler */ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == 0) { - signal_fd = s[0]; - signal_recv_fd = s[1]; - fcntl(s[0], F_SETFD, FD_CLOEXEC); - fcntl(s[0], F_SETFL, O_NONBLOCK); - fcntl(s[1], F_SETFD, FD_CLOEXEC); - fcntl(s[1], F_SETFL, O_NONBLOCK); - } -} - #define CRITICAL_CRASH_THRESHOLD 4 /* if we crash >4 times ... */ #define CRITICAL_CRASH_WINDOW (4*60) /* ... in 4 minutes, goto recovery*/ @@ -149,6 +126,31 @@ void handle_signal(void) ; } +void signal_init(void) +{ + int s[2]; + + struct sigaction act; + + act.sa_handler = sigchld_handler; + act.sa_flags = SA_NOCLDSTOP; + act.sa_mask = 0; + act.sa_restorer = NULL; + sigaction(SIGCHLD, &act, 0); + + /* create a signalling mechanism for the sigchld handler */ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == 0) { + signal_fd = s[0]; + signal_recv_fd = s[1]; + fcntl(s[0], F_SETFD, FD_CLOEXEC); + fcntl(s[0], F_SETFL, O_NONBLOCK); + fcntl(s[1], F_SETFD, FD_CLOEXEC); + fcntl(s[1], F_SETFL, O_NONBLOCK); + } + + handle_signal(); +} + int get_signal_fd() { return signal_recv_fd;