summaryrefslogtreecommitdiffstats
path: root/tests/timeout
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2025-11-28 17:34:23 +0000
committerPádraig Brady <P@draigBrady.com>2025-11-29 12:17:27 +0000
commitfc5c7b2e47fbe55034f4c8aa2f67caabcc5933dd (patch)
tree963874beede17f3fb4c8e54a2939e15ad51c5bd6 /tests/timeout
parentd1d311e7a244b908833fdae2f84fb5a613c055c7 (diff)
downloadcoreutils-fc5c7b2e47fbe55034f4c8aa2f67caabcc5933dd.tar.gz
coreutils-fc5c7b2e47fbe55034f4c8aa2f67caabcc5933dd.zip
timeout: ensure we terminate command upon abnormal exit
* src/timeout.c (main): Use PR_SET_PDEATHSIG to ensure the child is terminated even if the parent terminates abnormally. * tests/timeout/timeout-group.sh: Add a case to ensure sending SIGKILL results in the termination of the monitored command. * NEWS: Mention the improvement.
Diffstat (limited to 'tests/timeout')
-rwxr-xr-xtests/timeout/timeout-group.sh20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/timeout/timeout-group.sh b/tests/timeout/timeout-group.sh
index 81dadcf9d..ebe299f30 100755
--- a/tests/timeout/timeout-group.sh
+++ b/tests/timeout/timeout-group.sh
@@ -76,6 +76,13 @@ check_timeout_cmd_running()
{ sleep $delay; return 1; }
}
+check_timeout_cmd_exiting()
+{
+ local delay="$1"
+ test -e sig.received ||
+ { sleep $delay; return 1; }
+}
+
# Terminate any background processes
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
@@ -88,9 +95,20 @@ retry_delay_ check_timeout_cmd_running .1 6 || fail=1
kill -USR1 -- -$pid
wait
test -e sig.received || fail=1
-
rm -f sig.received timeout.running
+# On Linux ensure we kill the monitored command
+# even if we're terminated abnormally (e.g., get SIGKILL).
+if grep '^#define HAVE_PRCTL 1' "$CONFIG_HEADER" >/dev/null; then
+ timeout -sUSR1 25 ./timeout.cmd 20 & pid=$!
+ # Wait 6.3s for timeout.cmd to start
+ retry_delay_ check_timeout_cmd_running .1 6 || fail=1
+ kill -KILL -- $pid
+ wait
+ # Wait 6.3s for timeout.cmd to exit
+ retry_delay_ check_timeout_cmd_exiting .1 6 || fail=1
+ rm -f sig.received timeout.running
+fi
# Ensure cascaded timeouts work
# or more generally, ensure we timeout