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.
This commit is contained in:
Collin Funk 2025-12-02 19:16:23 -08:00
parent 86061ddbbd
commit c00a094188
3 changed files with 4 additions and 2 deletions

2
NEWS
View File

@ -42,6 +42,8 @@ GNU coreutils NEWS -*- outline -*-
timeout(1) in a shell backgrounded job, will not terminate upon receiving
SIGINT or SIGQUIT, as these are ignored by default in shell background jobs.
'timeout -v -s 0' now prints the signal number 0 instead of EXIT.
** Improvements
csplit, ls, and sort, now handle a more complete set of terminating signals.

View File

@ -232,7 +232,7 @@ cleanup (int sig)
if (verbose)
{
char signame[MAX (SIG2STR_MAX, INT_BUFSIZE_BOUND (int))];
if (sig2str (sig, signame) != 0)
if (sig == 0 || sig2str (sig, signame) != 0)
snprintf (signame, sizeof signame, "%d", sig);
error (0, 0, _("sending signal %s to command %s"),
signame, quote (command));

View File

@ -62,7 +62,7 @@ test "$out" = "" && test $status = 124 || fail=1
# Verify --verbose output
cat > exp <<\EOF
timeout: sending signal EXIT to command 'sleep'
timeout: sending signal 0 to command 'sleep'
timeout: sending signal KILL to command 'sleep'
EOF
for opt in -v --verbose; do