Bizarre interaction bug involving bash w/ lastpipe + Almquist 'wait'

Harald van Dijk harald at
Sat Feb 8 18:39:38 UTC 2020

On 07/02/2020 02:41, Robert Elz wrote:
>      Date:        Thu, 6 Feb 2020 16:12:06 +0000
>      From:        Martijn Dekker <martijn at>
>      Message-ID:  <10e3756b-5e8f-ba00-df0d-b36c93fa2281 at>
>    | NetBSD sh behaves differently. NetBSD 8.1 sh (as installed on
>    | and seem to act completely normally, but NetBSD 9.0rc2 sh
>    | (on my VirtualBox test VM) segfaults. Output on NetBSD 9.0rc2:
> I have updated my opinion on that, I think it is "don't have the bug",
> though it is possible a blocked SIGCHLD acts differently on NetBSD than
> on other systems.   On NetBSD it seems to affect nothing (the shell does
> not rely upon receiving SIGCHLD so not getting it is irrelevant) and
> the wait code when given an arg (as your script did) would always wait
> until that process exited, and return as soon as it did.

I think you're right that this isn't SIGCHLD behaving differently on 
NetBSD, it's that NetBSD sh does not have the same problem the other 
ash-based shells do. The problem is with sigsuspend, which in dash looks 

> 		sigblockall(&oldmask);
> 		while (!gotsigchld && !pending_sig)
> 			sigsuspend(&oldmask);
> 		sigclearmask();


This clearly cannot work when oldmask blocks SIGCHLD.

NetBSD sh does not use sigsuspend here, so avoids that problem.

I changed gwsh to call sigclearmask() on shell startup, but plan to 
check whether this loop is really necessary at some later time. It was 
added to dash to fix a race condition, where that race condition was 
apparently introduced by a fix for another race condition. If NetBSD sh 
manages to avoid this pattern, and assuming NetBSD sh is not still 
susceptible to one of those race conditions, the fix for it in the other 
shells would seem to be more complicated than necessary, and simplifying 
things would be good.

Harald van Dijk

More information about the busybox mailing list