]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
timeout: ensure --foreground -k exits with status 137
authorPádraig Brady <P@draigBrady.com>
Tue, 12 Oct 2021 13:32:57 +0000 (14:32 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 12 Oct 2021 13:32:57 +0000 (14:32 +0100)
* src/timeout.c (main): Propagate the killed status from the child.
* doc/coreutils.texi (timeout invocation): Remove the
description of the --foreground specific handling of SIGKILL,
now that it's consistent with the default mode of operation.
* tests/misc/timeout.sh: Add a test case.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/51135

NEWS
doc/coreutils.texi
src/timeout.c
tests/misc/timeout.sh

diff --git a/NEWS b/NEWS
index 1cb3c28a1aebd110887d4a9620567dedfe13dffb..086da03ae29200dc3b074fd5348b5bc126beb096 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,13 @@ GNU coreutils NEWS                                    -*- outline -*-
   All files would be processed correctly, but the exit status was incorrect.
   [bug introduced in coreutils-9.0]
 
+** Changes in behavior
+
+  timeout --foreground --kill-after=... will now exit with status 137
+  if the kill signal was sent, which is consistent with the behaviour
+  when the --foreground option is not specified.  This allows users to
+  distinguish if the command was more forcefully terminated.
+
 
 * Noteworthy changes in release 9.0 (2021-09-24) [stable]
 
index e3ecbdcf8657aaf33c3884631445bdb91a8a6ba5..02aae4ef4bb9657fdecefd6dda0effea7105de86 100644 (file)
@@ -18326,9 +18326,6 @@ exit status 137, regardless of whether that signal is sent to @var{command}
 or to @command{timeout} itself, i.e., these cases cannot be distinguished.
 In the latter case, the @var{command} process may still be alive after
 @command{timeout} has forcefully been terminated.
-However if the @option{--foreground} option is specified then
-@command{timeout} will not send any signals to its own process,
-and so it will exit with one of the other exit status values detailed above.
 
 Examples:
 
index 34d792640897581a2ffdc533f3367da51f990f5c..65056346172b918c10b7b9542991cbb3ada162c6 100644 (file)
@@ -593,6 +593,11 @@ main (int argc, char **argv)
                   unblock_signal (sig);
                   raise (sig);
                 }
+              /* Allow users to distinguish if command was forcably killed.
+                 Needed with --foreground where we don't send SIGKILL to
+                 the timeout process itself.  */
+              if (timed_out && sig == SIGKILL)
+                preserve_status = true;
               status = sig + 128; /* what sh returns for signaled processes.  */
             }
           else
index 44ca450d815024f3b63fdcc9d394997b1978293b..295a95773bba7054c58b35cc2e0a2b462e980018 100755 (executable)
@@ -42,7 +42,10 @@ returns_ 124 timeout --preserve-status .1 sleep 10 && fail=1
 # kill delay. Note once the initial timeout triggers,
 # the exit status will be 124 even if the command
 # exits on its own accord.
+# exit status should be 128+KILL
 returns_ 124 timeout -s0 -k1 .1 sleep 10 && fail=1
+# Ensure a consistent exit status with --foreground
+returns_ 124 timeout --foreground -s0 -k1 .1 sleep 10 && fail=1
 
 # Ensure 'timeout' is immune to parent's SIGCHLD handler
 # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh.