git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] t5570: fix forwarding of git-daemon messages via cat

From
Johannes Sixt <j6t@kdbg.org>
Date
Apr 26, 2012, 21:00 UTC
Message-ID
<4F99B777.4020103@kdbg.org>
In-Reply-To
<20120426195503.GA29526@ecki>

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>
---
Am 26.04.2012 21:55, schrieb Clemens Buchacher:
Show 8 quoted lines
> I won't pretend to understand why this works. I have to study this some
> more. But if this is 'correct', then it is obviously preferable to the
> comparatively complicated wrapper.
> 
> We should move the cat <&7 >&4 & and exec 7<&- part in front of the
> output check, otherwise output would be truncated in an error condition.
> This can be tested by passing an invalid argument to git daemon above,
> for example.
How about this?
 t/lib-git-daemon.sh |   22 +++++++++++-----------
 1 file 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() {
-- 
1.7.10.4.g51807
Previous: Clemens BuchacherNext: Zbigniew Jędrzejewski-Szmek
Message 16 of 20 in “t5570: forward git-daemon messages in a different way”
  1. t5570: forward git-daemon messages in a different wayZbigniew Jędrzejewski-Szmek, Apr 14, 2012
  2. Clemens BuchacherApr 14, 2012
  3. Clemens BuchacherApr 14, 2012
  4. Zbigniew Jędrzejewski-SzmekApr 16, 2012
  5. Junio C HamanoApr 16, 2012
  6. Clemens BuchacherApr 16, 2012
  7. Zbigniew Jędrzejewski-SzmekApr 16, 2012
  8. Junio C HamanoApr 17, 2012
  9. Jeff KingApr 16, 2012
  10. Clemens BuchacherApr 16, 2012
  11. Jeff KingApr 19, 2012
  12. Johannes SixtApr 19, 2012
  13. Jeff KingApr 26, 2012
  14. Johannes SixtApr 26, 2012
  15. Clemens BuchacherApr 26, 2012
  16. t5570: fix forwarding of git-daemon messages via catJohannes Sixt, Apr 26, 2012
  17. Zbigniew Jędrzejewski-SzmekApr 26, 2012
  18. Jeff KingApr 27, 2012
  19. Junio C HamanoApr 27, 2012
  20. Jeff KingApr 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.