]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
timeout: prioritize "timed out" exit status
authorPádraig Brady <P@draigBrady.com>
Tue, 2 Dec 2025 17:15:06 +0000 (17:15 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 2 Dec 2025 17:20:19 +0000 (17:20 +0000)
* src/timeout.c (cleanup): Reset the default exit status
to EXIT_TIMEDOUT, if we have in fact received an ALARM.
Otherwise we would exit with status EXIT_CANCELED if
there was an issue writing --verbose output for example.
This also ensures a consistent exit status with ASAN enabled,
as with ASAN stderr is not explicitly closed by gnulib's
close_stdout handler.

src/timeout.c
tests/timeout/timeout.sh

index 7634323d4b131c54add4526a21be480e4d0b5ae7..3303b57786b15bb6989a0d81385538e19c034c4f 100644 (file)
@@ -206,6 +206,12 @@ cleanup (int sig)
   if (sig == SIGALRM)
     {
       timed_out = 1;
+      /* In case there is an issue with close_stdout,
+         update to a more accurate default exit status.
+         For example we might get failed writes with -v with:
+           timeout -v 1 sleep 10 2>&1 | :
+      */
+      initialize_exit_failure (EXIT_TIMEDOUT);
       sig = term_signal;
     }
   if (0 < monitored_pid)
index 36dcba2d0a58a6df4ec55498b1d6bc646d332df1..c7d8a2906f9fb1f49f1035d866e7096cf3be432d 100755 (executable)
@@ -75,7 +75,7 @@ done
 # Specifically here we're testing that SIGPIPE is handled.
 # I.e., that we're not killed by the SIGPIPE (and leave the sleep running).
 # timeout would exit with 141 usually if SIGPIPE wasn't being handled.
-echo 125 > timeout.exp || framework_failure_
+echo 124 > timeout.exp || framework_failure_
 { timeout -v .1 sleep 10 2>&1; echo $? >timeout.status; } | :
 compare timeout.exp timeout.status || fail=1
 # Ensure we don't catch/propagate ignored signals