Fix a race condition between kern_wait() and thread_stopped().

Problem is in kern_wait(), parent process steps through children list,
once a child process is skipped, and later even if the child is stopped,
parent process still sleeps in msleep(), the race happens if parent
masked SIGCHLD.

Submitted by : Peter Edwards peadar.edwards at gmail dot com
MFC after    : 4 days
This commit is contained in:
davidxu 2005-04-19 08:07:28 +00:00
parent ed5a7da798
commit 02615ff23a
2 changed files with 6 additions and 1 deletions

View File

@ -743,7 +743,11 @@ kern_wait(struct thread *td, pid_t pid, int *status, int options,
}
PROC_LOCK(q);
sx_xunlock(&proctree_lock);
error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "wait", 0);
if (q->p_flag & P_STATCHILD) {
q->p_flag &= ~P_STATCHILD;
error = 0;
} else
error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "wait", 0);
PROC_UNLOCK(q);
if (error)
return (error);

View File

@ -638,6 +638,7 @@ struct proc {
#define P_JAILED 0x1000000 /* Process is in jail. */
#define P_INEXEC 0x4000000 /* Process is in execve(). */
#define P_STATCHILD 0x8000000 /* Child process stopped or exited. */
#define P_STOPPED (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE)
#define P_SHOULDSTOP(p) ((p)->p_flag & P_STOPPED)