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

Re: [PATCH] Portability: returning void

From
Jeff King <peff@peff.net>
Date
Mar 29, 2011, 22:36 UTC
Message-ID
<20110329223618.GC23510@sigill.intra.peff.net>
In-Reply-To
<20110329221652.GB23510@sigill.intra.peff.net>
On Tue, Mar 29, 2011 at 06:16:52PM -0400, Jeff King wrote:
Show 9 quoted lines
> On Tue, Mar 29, 2011 at 03:02:48PM -0500, Jonathan Nieder wrote:
> 
> > Next step is to figure out the longstanding mysterious bash + prove
> > hang in t0081.
>
> [...]
> 
>   2. Tests should kill their backgrounded sleeps themselves. I think I
>      saw some "kill $!" lines in there, but maybe we are missing one.

Indeed, those kill lines aren't doing what you expect. Try instrumenting like this:

diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh
index 1dbe1c9..3b2f8ce 100755
--- a/t/t0081-line-buffer.sh
+++ b/t/t0081-line-buffer.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 test_description="Test the svn importer's input handling routines.
 
@@ -56,6 +56,7 @@ long_read_test () {
 	binary $readsize
 	copy $copysize
 	EOF
+	echo >>/tmp/foo killing $!
 	kill $! &&
 	test_line_count = $lines output &&
 	tail -n 1 <output >actual &&
@@ -90,6 +91,7 @@ test_expect_success PIPE '0-length read, no input available' '
 	binary 0
 	copy 0
 	EOF
+	echo >>/tmp/foo killing $!
 	kill $! &&
 	test_cmp expect actual
 '
@@ -119,6 +121,7 @@ test_expect_success PIPE '1-byte read, no input available' '
 	binary 1
 	copy 1
 	EOF
+	echo >>/tmp/foo killing $!
 	kill $! &&
 	test_cmp expect actual
 '

And then run the test under prove, and check "ps" for remaining sleep
processes. You will see that the killed process IDs do not match up with
the sleep processes. Except for one sleep process, which actually got
killed. That is the second one in the list above. It works because it's:

  {
    sleep 100 >input &
  } &&
  ...
  kill $!

whereas the other ones are like:

  {
    do_something &&
    sleep 100
  } >input &

So my guess is that we have to start a subshell for the latter ones, and
_that_ is what gets killed. And that may explain the bash vs dash
behavior; dash, upon receiving the kill signal, presumably kills its
child, but bash does not (I didn't confirm that; it's just a theory).

I'm not sure what the best solution is. Perhaps putting the subshell
into its own process group and killing the whole PGRP?

-Peff
Previous: Jeff KingNext: Jonathan Nieder
Message 4 of 18 in “Portability: returning void”
  1. Portability: returning voidMichael Witten, Mar 29, 2011
  2. Jonathan NiederMar 29, 2011
  3. Jeff KingMar 29, 2011
  4. Jeff KingMar 29, 2011
  5. Jonathan NiederMar 29, 2011
  6. Jeff KingMar 30, 2011
  7. Jonathan NiederMar 30, 2011
  8. Jeff KingMar 30, 2011
  9. Jonathan NiederMar 30, 2011
  10. Jeff KingMar 30, 2011
  11. Johannes SixtMar 30, 2011
  12. tests: introduce helper to fill a pipe in the backgroundJonathan Nieder, Mar 30, 2011
  13. Jonathan NiederMar 30, 2011
  14. Jeff KingMar 30, 2011
  15. Jonathan NiederMar 30, 2011
  16. [PULL svn-fe] Re: Portability: returning voidJonathan Nieder, Mar 30, 2011
  17. Junio C HamanoMar 30, 2011
  18. Jonathan NiederMar 30, 2011

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.