supervise-daemon: reap zombies

We need to make sure to reap zombies so that we can shut down
successfully.

Fixes #252.
Possibly related to #250.
This commit is contained in:
William Hubbs 2018-11-05 21:35:00 -06:00
parent 025c9693cc
commit 008c9d0036

View File

@ -197,6 +197,16 @@ static void healthcheck(int sig)
do_healthcheck = 1; do_healthcheck = 1;
} }
static void reap_zombies(int sig)
{
int serrno;
(void) sig;
serrno = errno;
while (waitpid((pid_t)(-1), NULL, WNOHANG) > 0) {}
errno = serrno;
}
static char * expand_home(const char *home, const char *path) static char * expand_home(const char *home, const char *path)
{ {
char *opath, *ppath, *p, *nh; char *opath, *ppath, *p, *nh;
@ -457,6 +467,7 @@ static void supervisor(char *exec, char **argv)
signal_setup_restart(SIGPIPE, handle_signal); signal_setup_restart(SIGPIPE, handle_signal);
signal_setup_restart(SIGALRM, handle_signal); signal_setup_restart(SIGALRM, handle_signal);
signal_setup(SIGTERM, handle_signal); signal_setup(SIGTERM, handle_signal);
signal_setup(SIGCHLD, reap_zombies);
signal_setup_restart(SIGUSR1, handle_signal); signal_setup_restart(SIGUSR1, handle_signal);
signal_setup_restart(SIGUSR2, handle_signal); signal_setup_restart(SIGUSR2, handle_signal);
signal_setup_restart(SIGBUS, handle_signal); signal_setup_restart(SIGBUS, handle_signal);