Hi Pádraig,

Moving this to [email protected].

Pádraig Brady <[email protected]> writes:

>>> The system sig2str is fine.
>>>
>>> I'd probably prefer "0" rather than "EXIT" in the timeout.c code actually.
>>> I.e. use: if (sig == 0 || sig2str (sig, signame) != 0)
>>>
>>> EXIT comes from `trap foo 0` `trap foo EXIT` being equivalent,
>>> so it's probably slightly better for timeout to use "0" here.
>> Interesting. My preference is the opposite since I would always
>> write
>> 'trap foo EXIT'. Tiny exception for very old shells that don't support
>> signal names for 'trap'.
>> Also my change makes it compatible with what FreeBSD < 15.0 did. Not
>> that I expect it to cause any breakage.
>
> Sure, I also prefer `trap foo EXIT` in the _shell_ context.
> However in the timeout(1) context, EXIT might be confusing,
> as sending SIGEXIT to a process will not in fact cause it to exit.

True, that reasoning makes sense to me.

I'll push the attached patch tomorrow. I was debating if it was worth
adding a NEWS entry since it is a tiny change. But last time I
questioned that with a glibc patch it ended up breaking a program. :)

Collin

>From c00a0941881e36a71c999f50a51ac6d36b31558f Mon Sep 17 00:00:00 2001
Message-ID: <c00a0941881e36a71c999f50a51ac6d36b31558f.1764732253.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Tue, 2 Dec 2025 19:16:23 -0800
Subject: [PATCH] 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.
---
 NEWS                     | 2 ++
 src/timeout.c            | 2 +-
 tests/timeout/timeout.sh | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 445e8fb4a..127d70ae0 100644
--- a/NEWS
+++ b/NEWS
@@ -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.
diff --git a/src/timeout.c b/src/timeout.c
index 3303b5778..017078286 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -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));
diff --git a/tests/timeout/timeout.sh b/tests/timeout/timeout.sh
index c7d8a2906..3aaed93a7 100755
--- a/tests/timeout/timeout.sh
+++ b/tests/timeout/timeout.sh
@@ -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
-- 
2.52.0

Reply via email to