summaryrefslogtreecommitdiff
path: root/t/lib-git-daemon.sh
diff options
context:
space:
mode:
authorJohannes Sixt <j6t@kdbg.org>2012-04-26 21:00:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-04-27 15:01:33 (GMT)
commit46e358158109200abde4de0a044a415c80c9bce5 (patch)
treef679f7bff198637952f54af1e94a3dfc1431dc32 /t/lib-git-daemon.sh
parentfdec2eb8ebbf995a77e2ab9971565c792b52944a (diff)
downloadgit-46e358158109200abde4de0a044a415c80c9bce5.zip
git-46e358158109200abde4de0a044a415c80c9bce5.tar.gz
git-46e358158109200abde4de0a044a415c80c9bce5.tar.bz2
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 <j6t@kdbg.org> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/lib-git-daemon.sh')
-rw-r--r--t/lib-git-daemon.sh22
1 files changed, 11 insertions, 11 deletions
diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
index ef2d01f..87f0ad8 100644
--- a/t/lib-git-daemon.sh
+++ b/t/lib-git-daemon.sh
@@ -31,19 +31,19 @@ start_git_daemon() {
>&3 2>git_daemon_output &
GIT_DAEMON_PID=$!
{
- read line
+ read line <&7
echo >&4 "$line"
- cat >&4 &
+ cat <&7 >&4 &
+ } 7<git_daemon_output &&
- # Check expected output
- if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
- then
- kill "$GIT_DAEMON_PID"
- wait "$GIT_DAEMON_PID"
- trap 'die' EXIT
- error "git daemon failed to start"
- fi
- } <git_daemon_output
+ # Check expected output
+ if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
+ then
+ kill "$GIT_DAEMON_PID"
+ wait "$GIT_DAEMON_PID"
+ trap 'die' EXIT
+ error "git daemon failed to start"
+ fi
}
stop_git_daemon() {