Commit Graph
23 Commits
Author SHA1 Message Date
Pádraig Brady b4728bfa9b tests: timeout: fix false failure on some shells
The fix in commit v9.12-166-gb6b06854f was incomplete.
This is now tested to pass with SHELL=/bin/dash on Debian 10
(which otherwise defaults to bash even though /bin/sh is dash).

* tests/timeout/timeout.sh: Ensure the waiting shell's stderr
is not redirected to the full pipe, so any "Killed" message
does not block things.
2026-10-30 14:36:49 +00:00
Pádraig Brady b6b06854f3 tests: timeout: avoid false failure on some shells
dash in all modes, or bash when not invoked in posix mode
will issue a "Terminated" message and thus block with our filled pipe,
and not fire the trap.  I.e. with sh -> dash this test failed,
and sh -> bash this test passed (as bash is in POSIX mode in that case).
Interestingly this shows the shells have much the same problem
with stderr diagnostic side effects that timeout now avoids.

* tests/timeout/timeout.sh: Redirect the shell's stderr to /dev/null
so we don't care whether it outputs "Terminated" or not.  Also change
all "sh -c" to "$SHELL -c" for better consistency across all tests.
2026-10-29 14:51:21 +00:00
Pádraig Brady 46776b5e80 timeout: fix handling of --signal=CHLD and --signal=ALRM
These signals are used by timeout(1) itself, so need special handling.
Since commit v8.13-11-g80a1aca0d we incorrectly ignored them,
which was exacerbated by commit v8.26-39-g2f69dba5d which caused
the -sCHLD case to hang upon child exit.

* src/timeout.c (send_sig): Don't ignore SIGHLD, and discard
the self sent SIGALRM, and rearm the handler.
* tests/timeout/timeout.sh: Add test cases.
* NEWS: Mention the fixes.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-2EQL2L05.
2026-10-27 23:15:30 +00:00
Pádraig Brady 90843a2dc9 timeout: ensure we can --kill-after with blocked --verbose output
* NEWS: Adjust to mention that -k without -f is resilient to blocking.
* src/timeout.c (cleanup): Unblock SIGALRM when diagnosing, so
an armed --kill-after is honored.
* tests/timeout/timeout.sh: Add a test case.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-GV4Z4T3T.
2026-10-27 23:15:30 +00:00
Pádraig Brady 8fcaebfe47 timeout: ensure we timeout with --verbose failures
In the edge case where --verbose diagnostics might block
or induce signals, ensure we always timeout the monitored command
and do not loop diagnosing diagnostic induced signals.

* NEWS: Mention the bug fix.
* src/timeout.c (cleanup): Avoid diagnosing SIGPIPE and SIGXFSZ.
Also send the signal before diagnosing to ensure command is timed out.
* tests/env/env-signal-handler.sh: Run timeout(1) with -f to ensure
the SIGKILL is diagnosed.
* tests/timeout/timeout.sh: Likewise.  Also add test cases for
SIGPIPE and SIGXFSZ.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-GV4Z4T3T.
2026-10-27 23:15:30 +00:00
Pádraig Brady ff1141fcec tests: make process cleanup more robust
* tests/cat/cat-buf.sh: Always call 'wait' in case the process already
exited before being killed.
* tests/cp/existing-perm-race.sh: Likewise.
* tests/cp/file-perm-race.sh: Likewise.
* tests/cp/parent-perm-race.sh: Likewise.
* tests/cp/sparse-to-pipe.sh: Likewise.
* tests/du/move-dir-while-traversing.sh: Likewise.
* tests/help/help-version.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/mv/i-3.sh: Likewise.
* tests/printf/printf-surprise.sh: Likewise.
* tests/rm/isatty.sh: Likewise.
* tests/sort/sort-compress-proc.sh: Likewise.
* tests/sort/sort-spinlock-abuse.sh: Likewise.
* tests/tail/F-headers.sh: Likewise.
* tests/tail/F-vs-missing.sh: Likewise.
* tests/tail/F-vs-rename.sh: Likewise.
* tests/tail/append-only.sh: Likewise.
* tests/tail/assert-2.sh: Likewise.
* tests/tail/assert.sh: Likewise.
* tests/tail/debug.sh: Likewise.
* tests/tail/descriptor-vs-rename.sh: Likewise.
* tests/tail/follow-name.sh: Likewise.
* tests/tail/follow-stdin.sh: Likewise.
* tests/tail/follow-symlink.sh: Likewise.
* tests/tail/inotify-dir-recreate.sh: Likewise.
* tests/tail/inotify-hash-abuse.sh: Likewise.
* tests/tail/inotify-hash-abuse2.sh: Likewise.
* tests/tail/inotify-parent-hash.sh: Likewise.
* tests/tail/inotify-rotate.sh: Likewise.
* tests/tail/pid.sh: Likewise.
* tests/tail/pipe-f2.sh: Likewise.
* tests/tail/retry.sh: Likewise.
* tests/tail/symlink.sh: Likewise.
* tests/tail/tail-n0f.sh: Likewise.
* tests/tail/truncate.sh: Likewise.
* tests/tail/wait.sh: Likewise.
* tests/tee/tee.sh: Likewise.
* tests/timeout/timeout-group.sh: Likewise.
* tests/rm/dangling-symlink.sh: Likewise.
Also avoid redundant cleanup_ calls.
* tests/tail/flush-initial.sh: Likewise.
* tests/tail/inotify-rotate-resources.sh: Likewise.
2026-10-25 13:11:49 +00:00
Collin Funk e644eea122 timeout: don't exit immediately if the parent is the init process
* src/timeout.c (main): Save the process ID before creating a child
process. Check if the result of getppid is different than the saved
process ID instead of checking if it is 1.
* tests/timeout/init-parent.sh: New file.
* tests/local.mk (all_tests): Add the new test.
* NEWS: Mention the bug fix. Also mention that this change allows
'timeout' to work when reparented by a subreaper process instead of
init.
2026-03-13 20:37:10 -07:00
Pádraig Brady 8fab3c6d30 tests: fix "Hangup" termination of non-interactive runs
This avoids the test harness being terminated like:
  make[1]: *** [Makefile:24419: check-recursive] Hangup
  make[3]: *** [Makefile:24668: check-TESTS] Hangup
  make: *** [Makefile:24922: check] Hangup
  make[2]: *** [Makefile:24920: check-am] Hangup
  make[4]: *** [Makefile:24685: tests/misc/usage_vs_refs.log] Error 129
  ...

This happened sometimes when the tests were being run non interactively.
For example when run like:

  setsid make TESTS="tests/timeout/timeout.sh \
   tests/tail/overlay-headers.sh" SUBDIRS=. -j2 check

Note the race window can be made bigger by adding a sleep
after tail is stopped in overlay-headers.sh

The race can trigger the kernel to induce its job control
mechanism to prevent stuck processes.
I.e. where it sends SIGHUP + SIGCONT to a process group
when it determines that group may become orphaned,
and there are stopped processes in that group.

* tests/tail/overlay-headers.sh: Use setsid(1) to keep the stopped
tail process in a separate process group, thus avoiding any kernel
job control protection mechanism.
* tests/timeout/timeout.sh: Use setsid(1) to avoid the kernel
checking the main process group when sleep(1) is reparented.
Fixes https://bugs.gnu.org/80477
2026-02-24 19:25:58 +00:00
Collin Funk 73d3a49f45 maint: run 'make update-copyright' 2026-01-01 10:56:16 -08:00
Collin Funk c00a094188 timeout: print the signal number 0 instead of EXIT
POSIX.1-2024 added sig2str but leaves the behavior when called with
signal 0 unspecified. FreeBSD 15.0 does not return the signal name EXIT
like Gnulib's version causing a test failure. This fixes that and
changes the behavior to print 0 instead of EXIT, to avoid confusion when
the program does not exit.

* NEWS: Mention the change.
* src/timeout.c (cleanup): Use snprintf instead of sig2str if the signal
is 0.
* tests/timeout/timeout.sh: Updated the expected output.
2025-12-02 19:16:23 -08:00
Pádraig Brady 86061ddbbd timeout: prioritize "timed out" exit status
* 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.
2025-12-02 17:20:19 +00:00
Pádraig Brady faa566372d test: re-enable tests that had a false requirement on coreutils' kill
Recently we've not built our kill command by default,
so reduce test dependence on that.

* tests/sort/sort-compress-proc.sh: `kill -l [exit_status]` is well
supported, and is a POSIX requirement.
* tests/timeout/timeout.sh: There were actually no kill invocations
in this test at all.
2025-11-29 12:17:27 +00:00
Pádraig Brady fc5c7b2e47 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.
2025-11-29 12:17:27 +00:00
Pádraig Brady 8c24619334 timeout: honor ignored signal dispositions
This behavior was depended on in our trap_sigpipe_or_skip_ helper,
and now that we're handling all terminating signals, we should
consistently honor their ignored signal dispositions.

* NEWS: Mention the change in behavior, especially in regard
to shell background jobs.
* src/timeout.c (sig_needs_handling): A new helper that return TRUE,
for --signal, SIG_ALRM, or non ignored signals.
(cleanup_install): Filter handled signals with the helper.
(block_cleanup_and_chld): Likewise.
* tests/timeout/timeout-group.sh: Adjust to use the now required
`env --default-signal=...` wrapper to reset (auto) ignored signals.
Also change the termination signal from SIGINT to SIGUSR1
to generalize the test signals not specially handled by the shell,
and newly handled by timeout(1).
* tests/timeout/timeout.sh: Add a test case for SIGPIPE
to ensure the ignored signal disposition is honored.
2025-11-22 08:49:20 +00:00
Pádraig Brady d0a51c614d timeout: handle all terminating signals
* src/timeout.c (term_sig): A new global list of all signals
whose default disposition is to terminate the process.
(install_cleanup): Iterate over the TERM_SIG list, rather than
installing the handler for a specific subset.
(block_cleanup_and_chld): Likewise.
* tests/timeout/timeout.sh: Add a test case for SIGPIPE.
* NEWS: Mention the bug fix.
2025-11-21 12:12:28 +00:00
Pádraig Brady 4368d21fbd maint: adjustments to recent timeout change
* .gitignore: Add /lib/fenv.h to ignore list.
* tests/timeout/timeout-parameters.sh: Use a sleep length of 10s
to be consistent with the pattern where we use this larger time
when it does not slow down a test, but also provides protection
against a hung test, and better avoidance of false failures due
to races on very loaded systems.  Also fix the setting of FAIL.
* tests/timeout/timeout-large-parameters.sh: Remove duplicated test.
2025-04-05 11:37:58 +01:00
Paul Eggert a3b862ece2 timeout: round timeouts up
This handles timeouts like 16777216.000000001 correctly;
formerly the subsecond part of that timeout was ignored.
* bootstrap.conf (gnulib_modules): Add fenv-rounding, signbit.
* src/local.mk (src_timeout_LDADD): Append $(FENV_ROUNDING_LIBM).
* src/timeout.c: Include fenv.h, math.h.
Don’t include xstrtod.h, as xstrtod’s checking now gets in the way.
(parse_duration): Round up when calling cl_strtod.
Check for -1e-1000.  Don’t double-round 1e-9.
* tests/timeout/timeout-parameters.sh: Test for -0.1,
-1e-1000, 1e-1000.
2025-04-05 00:58:58 -07:00
Pádraig Brady 026d0d7c40 timeout: ensure infinitesimal timeouts timeout quickly
* src/timeout.c (parse_duration): Clamp infinitesimal values to 1ns.
* tests/timeout/timeout-large-parameters.sh: Add a test case.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/77535
2025-04-04 20:52:32 +01:00
Pádraig Brady 28b176085f maint: update all copyright year number ranges
Update to latest gnulib with new copyright year.
Run "make update-copyright" and then...

* gnulib: Update included in this commit as copyright years
are the only change from the previous gnulib commit.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
* tests/sample-test: Adjust to use the single most recent year.
2025-01-01 09:33:08 +00:00
Pádraig Brady 69aaec486f doc: fix timeout --help for -p
* src/timeout.c (usage): Fix typo of period with comma.
* tests/timeout/timeout.sh: Only test a single option variant,
as tests/misc/usage_vs_getopt.sh suffices for basic option validation.
2024-11-01 12:49:44 +00:00
Pádraig Brady f4fbc1a9f9 timeout: add -f and -p short options as per POSIX 2024
* src/timeout.c: Support -f and -p short options, corresponding to
--foreground and --preserve-status respectively.  This adds
compatability with POSIX 2024 and OpenBSD.
(usage): Separate translations, and reorder the option descriptions.
* doc/coreutils.texi (timeout invocation): Adjust accordingly,
and also reorder the option descriptions alphabetically.
* tests/timeout/timeout.sh: Also test short option variants.
2024-10-30 12:49:26 +00:00
Pádraig Brady a966dcdb69 maint: update all copyright year number ranges
Update to latest gnulib with new copyright year.
Run "make update-copyright" and then...

* gnulib: Update included in this commit as copyright years
are the only change from the previous gnulib commit.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Manually update copyright year,
until we fully sync with gnulib at a later stage.
* tests/sample-test: Adjust to use the single most recent year.
2024-01-01 13:27:23 +00:00
Sylvestre Ledru 15925d0e5b tests: move tests to a directory per utility
* cfg.mk: Adjust syntax check exclusion paths.
* tests/local.mk: Adjust for renamed tests.
2023-06-19 13:12:37 +01:00