Patch by Guillaume Morin

Fix two race conditions, as described at.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=212764
This commit is contained in:
Glenn L McGrath 2003-09-26 10:45:55 +00:00
parent f7dd10f67c
commit e6ba16f830

View File

@ -500,7 +500,12 @@ static pid_t run(const struct init_action *a)
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_DFL);
/* Wait for child to exit */ /* Wait for child to exit */
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid); while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
if (tmp_pid == -1 && errno == ECHILD) {
break;
}
/* FIXME handle other errors */
}
/* See if stealing the controlling tty back is necessary */ /* See if stealing the controlling tty back is necessary */
pgrp = tcgetpgrp(0); pgrp = tcgetpgrp(0);
@ -624,12 +629,15 @@ static int waitfor(const struct init_action *a)
pid = run(a); pid = run(a);
while (1) { while (1) {
wpid = wait(&status); wpid = waitpid(pid,&status,0);
if (wpid > 0 && wpid != pid) {
continue;
}
if (wpid == pid) if (wpid == pid)
break; break;
if (wpid == -1 && errno == ECHILD) {
/* we missed its termination */
break;
}
/* FIXME other errors should maybe trigger an error, but allow
* the program to continue */
} }
return wpid; return wpid;
} }