mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-02-16 12:22:01 +02:00
These issues were seen on an OpenSuse 10.3 system (kernel 2.6.22.5 x86_64, glibc 2.6.1-18, bash updated to 4.2), and also on a 64 bit SLES system with a 2.6.16 kernel. Both systems had 2 CPUs. There were two issues seen. 1. Occasionally the timeout.cmd shell script would block SIGINT until the sleep command exited. 2. Much less frequently the signal handler in the timeout command itself was ignored, causing SIGALRM to kill the process. * tests/misc/timeout-group: Detect the above two cases, and skip rather than fail. Note only issue 2. causes a failure unless skipped, but we skip for case 1. also, for diagnostic purposes.
98 lines
2.7 KiB
Bash
Executable File
98 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# test program group handling
|
|
|
|
# Copyright (C) 2011 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
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
|
print_ver_ timeout
|
|
|
|
# construct a program group hierarchy as follows:
|
|
# timeout-group - foreground group
|
|
# group.sh - separate group
|
|
# timeout.cmd - same group as group.sh
|
|
#
|
|
# We then send a SIGINT to the "separate group"
|
|
# to simulate what happens when a Ctrl-C
|
|
# is sent to the foreground group.
|
|
|
|
setsid true || skip_ "setsid required to control groups"
|
|
|
|
cat > timeout.cmd <<\EOF
|
|
#!/bin/sh
|
|
trap 'touch int.received; exit' INT
|
|
touch timeout.running
|
|
sleep $1
|
|
EOF
|
|
chmod a+x timeout.cmd
|
|
|
|
cat > group.sh <<\EOF
|
|
#!/bin/sh
|
|
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 &
|
|
# 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 -- -$!
|
|
wait
|
|
test -e int.received || fail=1
|
|
|
|
rm -f int.received timeout.running
|
|
|
|
|
|
# Ensure cascaded timeouts work
|
|
# or more generally, ensure we timeout
|
|
# commands that create their own group
|
|
# This didn't work before 8.13.
|
|
|
|
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=$!
|
|
# 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
|
|
wait $pid
|
|
ret=$?
|
|
test $ret -eq 124 ||
|
|
skip_ "timeout returned $ret. SIGALRM not handled?"
|
|
test -e int.received || fail=1
|
|
|
|
end=$(date +%s)
|
|
|
|
test $(expr $end - $start) -lt 20 ||
|
|
skip_ "timeout.cmd didn't receive a signal until after sleep?"
|
|
|
|
Exit $fail
|