summaryrefslogtreecommitdiff
path: root/tests/misc/timeout-group.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/timeout-group.sh')
-rwxr-xr-xtests/misc/timeout-group.sh19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh
index 23c1b065..d47f0dc8 100755
--- a/tests/misc/timeout-group.sh
+++ b/tests/misc/timeout-group.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# test program group handling
-# Copyright (C) 2011-2014 Free Software Foundation, Inc.
+# Copyright (C) 2011-2015 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@ print_ver_ timeout
setsid true || skip_ "setsid required to control groups"
-cat > timeout.cmd <<\EOF
-#!/bin/sh
+printf '%s\n' '#!'"$SHELL" > timeout.cmd || framework_failure_
+cat >> timeout.cmd <<\EOF
trap 'touch int.received; exit' INT
touch timeout.running
count=$1
@@ -42,8 +42,8 @@ done
EOF
chmod a+x timeout.cmd
-cat > group.sh <<\EOF
-#!/bin/sh
+cat > group.sh <<EOF
+#!$SHELL
trap '' INT
timeout --foreground 25 ./timeout.cmd 20&
wait
@@ -57,15 +57,17 @@ check_timeout_cmd_running()
{ sleep $delay; return 1; }
}
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
# Start above script in its own group.
# We could use timeout for this, but that assumes an implementation.
-setsid ./group.sh &
+setsid ./group.sh & pid=$!
# 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 -- -$!
+env kill -INT -- -$pid
wait
test -e int.received || fail=1
@@ -82,8 +84,7 @@ start=$(date +%s)
# 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 30 timeout -sINT 25 ./timeout.cmd 20&
-pid=$!
+timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20 & pid=$!
# Wait 6.3s for timeout.cmd to start
retry_delay_ check_timeout_cmd_running .1 6 || fail=1
kill -ALRM $pid # trigger the alarm of the first timeout command