Bug 5600

Summary: ash shell backtick never returns if sub-process closes std file descriptors
Product: Busybox Reporter: Jim Edwards <jimbo-busybox>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.19.x   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description Jim Edwards 2012-10-11 20:09:15 UTC
It seems there is some kind of a problem in the ash shells implementation of back-tick (or variable execution).  If you try and start a process which closes the stdout/stderr file-descriptors in the back-tick, then the back-tick operation never returns, even though the sub-process has exited.  This was originally report when udev was started as a daemon, for example:

echo "Running UDEV"
OUPUT=`udevd -d`
echo "Returned ${OUTPUT}"

would output:

Running UDEV
<hang forever>

I noticed back in 2003 there was a patch for a similar problem for the msh shell in busybox.
Comment 1 Denys Vlasenko 2012-10-15 13:55:46 UTC
Trying to reproduce:

$ strace -oLOG -s99 -f -tt ./busybox ash -c 'echo T1 `exec <&- >&- 2>&-` T2'
T1 T2
$

and strace log looks normal.
Adding a pause:

$ ./busybox ash -c 'echo T1 `exec <&- >&- 2>&-; exec sleep 1` T2'
<one second pause>
T1 T2
$

Still looks ok.

Are you sure that in your case: OUPUT=`udevd -d`, udevd does not forget to close stdout when it daemonizes? If it does, then shell will be blocked reading from it. Try OUPUT=`udevd -d </dev/null >/dev/null 2>&1`