]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: fix a race in timeout-group
authorPádraig Brady <P@draigBrady.com>
Thu, 13 Oct 2011 13:58:58 +0000 (14:58 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 3 Nov 2011 18:36:28 +0000 (18:36 +0000)
This could cause a false failure, or even
an infinite loop in rare circumstances.

* tests/misc/timeout-group: Increase the timeouts
passed to the timeout command, so that they're
effectively not used.  Instead the command termination
is triggered by the kill commands when everything
is in the correct state.

Reported by Bernhard Voelker.

tests/misc/timeout-group

index fedd53a608dc093c2b46200091ff97e9a1f3a50c..5d31551d303733ca6a0a73f8a8b7a8e8b65efc0d 100755 (executable)
@@ -40,15 +40,25 @@ chmod a+x timeout.cmd
 
 cat > group.sh <<\EOF
 #!/bin/sh
-timeout --foreground 5 ./timeout.cmd 10&
+trap '' INT
+timeout --foreground 25 ./timeout.cmd 20&
 wait
 EOF
 chmod a+x group.sh
 
+check_timeout_cmd_running()
+{
+  local delay="$1"
+  test -e timeout.running ||
+    { sleep $delay; return 1; }
+}
+
+
 # Start above script in its own group.
 # We could use timeout for this, but that assumes an implementation.
 setsid ./group.sh &
-until test -e timeout.running; do sleep .1; done
+# Wait 6.3s for timeout.cmd to start
+retry_delay_ check_timeout_cmd_running .1 6 || fail=1
 # Simulate a Ctrl-C to the group to test timely exit
 # Note dash doesn't support signalling groups (a leading -)
 env kill -INT -- -$!
@@ -66,9 +76,10 @@ rm -f int.received timeout.running
 # Note the first timeout must send a signal that
 # the second is handling for it to be propagated to the command.
 # SIGINT, SIGTERM, SIGALRM etc. are implicit.
-timeout -sALRM 2 timeout -sINT 10 ./timeout.cmd 5&
-until test -e timeout.running; do sleep .1; done
-kill -ALRM $!
+timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20&
+# Wait 6.3s for timeout.cmd to start
+retry_delay_ check_timeout_cmd_running .1 6 || fail=1
+kill -ALRM $! # trigger the alarm of the first timeout command
 wait
 test -e int.received || fail=1