Skip to content

Commit 46e3581

Browse files
j6tgitster
authored andcommitted
t5570: fix forwarding of git-daemon messages via cat
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 <git_daemon_output cat <git_daemon_output >&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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fdec2eb commit 46e3581

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

t/lib-git-daemon.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ start_git_daemon() {
3131
>&3 2>git_daemon_output &
3232
GIT_DAEMON_PID=$!
3333
{
34-
read line
34+
read line <&7
3535
echo >&4 "$line"
36-
cat >&4 &
36+
cat <&7 >&4 &
37+
} 7<git_daemon_output &&
3738

38-
# Check expected output
39-
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
40-
then
41-
kill "$GIT_DAEMON_PID"
42-
wait "$GIT_DAEMON_PID"
43-
trap 'die' EXIT
44-
error "git daemon failed to start"
45-
fi
46-
} <git_daemon_output
39+
# Check expected output
40+
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
41+
then
42+
kill "$GIT_DAEMON_PID"
43+
wait "$GIT_DAEMON_PID"
44+
trap 'die' EXIT
45+
error "git daemon failed to start"
46+
fi
4747
}
4848

4949
stop_git_daemon() {

0 commit comments

Comments
 (0)