diff options
author | Pádraig Brady <P@draigBrady.com> | 2011-07-06 23:17:10 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2011-07-08 11:23:08 +0100 |
commit | 4496c94091f8a6bc95fc1c0868eba632fae99ba3 (patch) | |
tree | 44e2b1a618a781abeb02a639387efcf6320abbed /tests/misc | |
parent | 28a7fb52bc1160ffe1acac2e4fc3fa495d021ec4 (diff) | |
download | coreutils-4496c94091f8a6bc95fc1c0868eba632fae99ba3.tar.xz |
timeout: add --foreground to support interactive commands
Or more accurately, commands not started from the shell prompt,
that are interactive, or need to receive Ctrl-C etc. from the terminal.
* doc/coreutils.texi (timeout invocation): Document --foreground.
* src/timeout.c (main): Set the foreground flag and don't create
a separate group.
(cleanup): Only send a signal directly to the monitored command
when the foreground flag is set.
(usage): Describe --foreground.
* tests/misc/timeout-group: Add a new test.
* tests/Makefile.am: Reference new test.
NEWS: Mention the new option.
Reported by Shay Shimony
Analysis by Alan Curry
Fix suggested by Paul Eggert
Diffstat (limited to 'tests/misc')
-rwxr-xr-x | tests/misc/timeout-group | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/misc/timeout-group b/tests/misc/timeout-group new file mode 100755 index 000000000..0c3caa0f0 --- /dev/null +++ b/tests/misc/timeout-group @@ -0,0 +1,58 @@ +#!/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 10 +EOF +chmod a+x timeout.cmd + +cat > group.sh <<\EOF +#!/bin/sh +timeout --foreground 5 ./timeout.cmd& +wait +EOF +chmod a+x group.sh + +# 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 +# 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 + +Exit $fail |