From: Zbigniew Jędrzejewski-Szmek Date: Thu, 26 Apr 2012 21:10:26 GMT Subject: Re: [PATCH] t5570: fix forwarding of git-daemon messages via cat Message-ID: <4F99B9C2.7090805@in.waw.pl> In-Reply-To: <4F99B777.4020103@kdbg.org> On 04/26/2012 11:00 PM, Johannes Sixt wrote: > The shell function that starts git-daemon wants to read the first line of > the daemon's stderr to ensure that it started correctly. Subsequent daemon > errors should be redirected to fd 4 (which is the terminal in verbose mode > or /dev/null in quiet mode). To that end the shell script used 'read' to > get the first line of output, and then 'cat &' to forward everything else > in a background process. > > The problem is, that 'cat >&4 &' does not produce any output because the > shell redirects a background process's stdin to /dev/null. To have this > command invocation do anything useful, we have to redirect its stdin > explicitly (which overrides the /dev/null redirection). > > The shell function connects the daemon's stderr to its consumers via a > FIFO. We cannot just do this: > > read line cat &4 & > > because after the first redirection the pipe is closed and the daemon > could receive SIGPIPE if it writes at the wrong moment. Therefore, we open > the readable end of the FIFO only once on fd 7 in the shell and dup from > there to the stdin of the two consumers. > > Signed-off-by: Johannes Sixt Beautiful explanation. Thanks! I can confirm that this fix works for me. - Zbyszek