Date: Wed, 7 Mar 2007 08:20:09 GMT From: "Jukka A. Ukkonen" <jau@oxit.fi> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/109946: [kernel] [patch] Compatibility: FreeBSD has been missing WNOWAIT flag for wait*() calls://undefined Message-ID: <200703070820.l278K9Si055520@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/109946; it has been noted by GNATS. From: "Jukka A. Ukkonen" <jau@oxit.fi> To: bug-followup@FreeBSD.org, jau@iki.fi Cc: Subject: Re: kern/109946: [kernel] [patch] Compatibility: FreeBSD has been missing WNOWAIT flag for wait*() calls://undefined Date: Wed, 07 Mar 2007 10:06:28 +0200 This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_singer-1914-1173254800-0001-2 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Oops! Reverse the if-condition to read if (options & WNOWAIT) { The version I attached seems to be an older diff which I - obviously - cannot be using myself, because doing the the wrong way would quickly end up never cleaning the zombies away from the proc table. I originally intended to do the test the other way around enveloping the whole proc entry cleanup in an if block, but then I decided to favour readability and to cut the whole thing short by unlocking and returning early. The bad news is I made an intermediate diff for myself while I had already added shortcut return but had not yet reversed the if-test. Though I made another diff after changing the if-test direction as well, I still somehow managed to attach the wrong one to the PR. Sigh! Additionally it might make sense to do the shortcut return already before the "ptrace attach" test/block but after the PROC_UNLOCK(p); line when rusage has been filled in. So, I attach a modified patch which in addition to showing the proper WNOWAIT test also moves the WNOWAIT test before the ptrace attach test. Cheers, // jau --=_singer-1914-1173254800-0001-2 Content-Type: text/x-patch; name="wait-WNOWAIT.patch"; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="wait-WNOWAIT.patch" --- src/sys/sys/wait.h.orig Mon Mar 5 20:11:30 2007 +++ src/sys/sys/wait.h Mon Mar 5 20:40:32 2007 @@ -78,7 +78,9 @@ */ #define WNOHANG 1 /* Don't hang in wait. */ #define WUNTRACED 2 /* Tell about stopped, untraced children. */ +#define WSTOPPED WUNTRACED /* SUS compatibility */ #define WCONTINUED 4 /* Report a job control continued process. */ +#define WNOWAIT 8 /* Poll only. Don't delete the proc entry. */ #if __BSD_VISIBLE #define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */ --- src/sys/kern/kern_exit.c.orig Mon Mar 5 20:17:19 2007 +++ src/sys/kern/kern_exit.c Wed Mar 7 09:46:01 2007 @@ -590,7 +590,7 @@ 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) { @@ -650,11 +650,32 @@ calcru(p, &rusage->ru_utime, &rusage->ru_stime); } + PROC_UNLOCK(p); + + if (options & WNOWAIT) { + /* + * SUS compatibility. + * + * We poll only returning the status. + * We do not wish to release the proc + * struct just yet. + * ==> If another thread created this + * process, it is sometimes better to + * leave this one as is for now and let + * the other thread reap the remnants + * of the child instead of automatically + * destroying the proc entry and making + * it impossible for the other thread to + * wait for its own child process. + */ + 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; --=_singer-1914-1173254800-0001-2--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200703070820.l278K9Si055520>