2 # test program group handling
4 # Copyright (C) 2011-2016 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
24 # construct a program group hierarchy as follows:
25 # timeout-group - foreground group
26 # group.sh - separate group
27 # timeout.cmd - same group as group.sh
29 # We then send a SIGINT to the "separate group"
30 # to simulate what happens when a Ctrl-C
31 # is sent to the foreground group.
33 setsid true || skip_
"setsid required to control groups"
35 printf '%s\n' '#!'"$SHELL" > timeout.cmd || framework_failure_
36 cat >> timeout.cmd
<<\EOF
37 trap 'touch int.received; exit' INT
40 until test -e int.received ||
test $count = 0; do
42 count
=$
(expr $count - 1)
50 timeout --foreground 25 ./timeout.cmd 20&
55 check_timeout_cmd_running
()
58 test -e timeout.running ||
59 { sleep $delay; return 1; }
62 # Terminate any background processes
63 cleanup_
() { kill $pid 2>/dev
/null
&& wait $pid; }
65 # Start above script in its own group.
66 # We could use timeout for this, but that assumes an implementation.
67 setsid .
/group.sh
& pid
=$
!
68 # Wait 6.3s for timeout.cmd to start
69 retry_delay_ check_timeout_cmd_running
.1 6 || fail
=1
70 # Simulate a Ctrl-C to the group to test timely exit
73 test -e int.received || fail
=1
75 rm -f int.received timeout.running
78 # Ensure cascaded timeouts work
79 # or more generally, ensure we timeout
80 # commands that create their own group
81 # This didn't work before 8.13.
85 # Note the first timeout must send a signal that
86 # the second is handling for it to be propagated to the command.
87 # SIGINT, SIGTERM, SIGALRM etc. are implicit.
88 timeout
-sALRM 30 timeout
-sINT 25 .
/timeout.cmd
20 & pid
=$
!
89 # Wait 6.3s for timeout.cmd to start
90 retry_delay_ check_timeout_cmd_running
.1 6 || fail
=1
91 kill -ALRM $pid # trigger the alarm of the first timeout command
95 skip_
"timeout returned $ret. SIGALRM not handled?"
96 test -e int.received || fail
=1
100 test $
(expr $end - $start) -lt 20 ||
101 skip_
"timeout.cmd didn't receive a signal until after sleep?"