--- src/init.c +++ src/init.c 2005-10-19 10:01:15.000000000 +0000 @@ -20,6 +20,14 @@ * */ +/* + * 4 Sep 2001, Andrea Arcangeli: + * Fix a race in spawn() that is used to deadlock init in a + * waitpid() loop: must set the childhandler as default before forking + * off the child or the chld_handler could run before the waitpid loop + * has a chance to find its zombie-child. + */ + #include #include #include @@ -976,6 +984,7 @@ int spawn(CHILD *ch, int *res) dup(f); dup(f); } + SETSIG(sa, SIGCHLD, SIG_DFL, SA_RESTART); if ((pid = fork()) < 0) { initlog(L_VB, "cannot fork"); exit(1); @@ -988,7 +997,6 @@ int spawn(CHILD *ch, int *res) SETSIG(sa, SIGINT, SIG_IGN, SA_RESTART); SETSIG(sa, SIGTSTP, SIG_IGN, SA_RESTART); SETSIG(sa, SIGQUIT, SIG_IGN, SA_RESTART); - SETSIG(sa, SIGCHLD, SIG_DFL, SA_RESTART); while ((rc = waitpid(pid, &st, 0)) != pid) if (rc < 0 && errno == ECHILD)