Collin Funk wrote:
> FreeBSD added sig2str which makes tests/timeout/timeout.sh from
> coreutils fail with the following:
>
> + compare_ exp err
> + LC_ALL=C diff -u exp err
> --- exp 2025-12-01 21:18:13.335894000 -0800
> +++ err 2025-12-01 21:18:13.790449000 -0800
> @@ -1,2 +1,2 @@
> -timeout: sending signal EXIT to command 'sleep'
> +timeout: sending signal 0 to command 'sleep'
> timeout: sending signal KILL to command 'sleep'
>
> POSIX states [1]:
>
> If signum is equal to 0, the behavior is unspecified.
>
> This seems like an uncommon use of this function, so I am tempted to
> push this change to coreutils:
>
> diff --git a/src/timeout.c b/src/timeout.c
> index 7634323d4..cea997161 100644
> --- a/src/timeout.c
> +++ b/src/timeout.c
> @@ -226,7 +226,9 @@ cleanup (int sig)
> if (verbose)
> {
> char signame[MAX (SIG2STR_MAX, INT_BUFSIZE_BOUND (int))];
> - if (sig2str (sig, signame) != 0)
> + if (sig == 0)
> + strcpy (signame, "EXIT");
> + else if (sig2str (sig, signame) != 0)
> snprintf (signame, sizeof signame, "%d", sig);
> error (0, 0, _("sending signal %s to command %s"),
> signame, quote (command));
I fully agree with that.
> However, I figured it was best to get others opinions first. Is it worth
> replacing the system sig2str in this case?
We would need to have two modules 'sig2str-posix' and 'sig2str-gnu'.
Not worth it, in my opinion.
All we should do in Gnulib is to document the portability problem:
2025-12-02 Bruno Haible <[email protected]>
doc: Mention a portability problem of sig2str.
Reported by Collin Funk in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-12/msg00007.html>.
* doc/posix-functions/sig2str.texi: Mention the argument 0 problem.
diff --git a/doc/posix-functions/sig2str.texi b/doc/posix-functions/sig2str.texi
index dba8a7abec..6dedd2fad1 100644
--- a/doc/posix-functions/sig2str.texi
+++ b/doc/posix-functions/sig2str.texi
@@ -16,4 +16,7 @@
Portability problems not fixed by Gnulib:
@itemize
+@item
+This function does not map the argument 0 to @code{"EXIT"} on some platforms:
+FreeBSD 15.0.
@end itemize