diff options
author | Pádraig Brady <P@draigBrady.com> | 2011-10-13 14:58:58 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2011-11-03 18:36:28 +0000 |
commit | aa6448b8d506e8948f0ef0239e23019ef9566a98 (patch) | |
tree | f2f18792fbde35c667dc3c97a16627ba6f60d5e4 /tests/misc/timeout-group | |
parent | d84d8764ccfdf9138723765aa7b1b4f604ba6a94 (diff) | |
download | coreutils-aa6448b8d506e8948f0ef0239e23019ef9566a98.tar.xz |
tests: fix a race in timeout-group
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.
Diffstat (limited to 'tests/misc/timeout-group')
-rwxr-xr-x | tests/misc/timeout-group | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/misc/timeout-group b/tests/misc/timeout-group index fedd53a60..5d31551d3 100755 --- a/tests/misc/timeout-group +++ b/tests/misc/timeout-group @@ -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 |