sysvinit/sysvinit-2.86-race.patch

36 lines
1.0 KiB
Diff

Index: src/init.c
===================================================================
--- src/init.c.orig
+++ src/init.c
@@ -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 <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -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)