summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2010-04-16 20:28:11 -0700
committerColin Cross <ccross@android.com>2010-04-21 19:43:35 -0700
commit12541c61311e0488e9873df754f8328cd12f99b4 (patch)
tree176dc830dcd1b6063d1a04d8f0f9e7e27401e1bb
parentb0ab94b7d5a888f0b6920b156e5c6a075fa0741a (diff)
downloadsystem_core-12541c61311e0488e9873df754f8328cd12f99b4.zip
system_core-12541c61311e0488e9873df754f8328cd12f99b4.tar.gz
system_core-12541c61311e0488e9873df754f8328cd12f99b4.tar.bz2
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
-rw-r--r--init/signal_handler.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/init/signal_handler.c b/init/signal_handler.c
index b16eef1..e5d308d 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;