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
This commit is contained in:
parent
b0ab94b7d5
commit
12541c6131
1 changed files with 25 additions and 23 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue