From 05dac85e4b0f1f608662dcda515b72680edf8348 Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 26 Aug 2008 12:37:16 +0000 Subject: Implement WNOWAIT flag for wait4(2). It specifies that process whose status is returned shall be kept in the waitable state. Add WSTOPPED as an alias for WUNTRACED. Submitted by: Jukka Ukkonen PR: standards/116221 MFC after: 2 weeks --- sys/kern/kern_exit.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_exit.c') diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index f0866ed..b536d99 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -690,7 +690,7 @@ kern_wait(struct thread *td, pid_t pid, int *status, int options, pid = -q->p_pgid; PROC_UNLOCK(q); } - if (options &~ (WUNTRACED|WNOHANG|WCONTINUED|WLINUXCLONE)) + if (options &~ (WUNTRACED|WNOHANG|WCONTINUED|WNOWAIT|WLINUXCLONE)) return (EINVAL); loop: if (q->p_flag & P_STATCHILD) { @@ -741,11 +741,23 @@ loop: sigqueue_take(p->p_ksi); PROC_UNLOCK(q); + PROC_UNLOCK(p); + + if (options & WNOWAIT) { + + /* + * Only poll, returning the status. + * Caller does not wish to release the proc + * struct just yet. + */ + sx_xunlock(&proctree_lock); + return (0); + } + /* * If we got the child via a ptrace 'attach', * we need to give it back to the old parent. */ - PROC_UNLOCK(p); if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) { PROC_LOCK(p); p->p_oppid = 0; -- cgit v1.1