Re: wait code is fishy

Herbert Xu <[email protected]> Mon, 25 Aug 2025 17:53:35 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Mon, Aug 11, 2025 at 06:30:10PM +0200, Denys Vlasenko wrote:
>
> If we got pid == 0, it happens in exactly one case:
> we did waitpid(WNOHANG), got 0 ("children exist but none yet
> changed its state"), then waited for a signal and got one,
> which wasn't SIGCHLD.

The pid == 0 case only happens on a blocking wait + signal, not
on a non-blocking wait.  A non-blocking wait would return with
err == -1.

> It's ok to leave the logic unchanged, but perhaps it should be
> tweaked to be more understandable. Unreadable code snippet example:
> 
>                 if (err || (err = -!block))
>                         break;
> 
> Assignment in the conditional, just what we need to be confused.

Yes patches to reorganise this are welcome.  But please make each
change small and easy to review as this area is complicated and
bug-prone.

Cheers,
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt