From 7e5b6b6f076afd4e9bcf2507efb496c63c026363 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Sat, 21 Dec 2024 12:54:59 +0000 Subject: [PATCH] kill: with -l,-t list signal 0 The 0 (EXIT) signal is valid as input (and useful to determine existence of a pid), so list it along with other signals. * doc/coreutils.texi (signal specifications): Document 0, "EXIT". * src/kill.c (list_signals): Start loops at 0, not 1. * tests/misc/kill.sh: Add a test case. * NEWS: Mention the change in behavior. --- NEWS | 2 ++ doc/coreutils.texi | 12 ++++++++++-- src/kill.c | 6 +++--- tests/misc/kill.sh | 3 +++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 9c6f2fb0d..f76393506 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,8 @@ GNU coreutils NEWS -*- outline -*- install -C now dereferences symlink sources when comparing, rather than always treating as different and performing the copy. + kill -l and -t now list signal 0, as it's a valid signal to send. + ls's -f option now simply acts like -aU, instead of also ignoring some earlier options. For example 'ls -fl' and 'ls -lf' are now equivalent because -f no longer ignores an earlier -l. The new diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 39a9ac05f..11a51706b 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -1083,8 +1083,16 @@ apparent file sizes, whereas the @option{--block-size} option does. A @var{signal} may be a signal name like @samp{HUP}, or a signal number like @samp{1}, or an exit status of a process terminated by the signal. A signal name can be given in canonical form or prefixed by -@samp{SIG}@. The case of the letters is ignored. The following signal names -and numbers are supported on all POSIX compliant systems: +@samp{SIG}@. The case of the letters is ignored. + +@noindent +The signal @samp{0} pseudo signal is synonymous with the name @samp{EXIT} +with the GNU @command{kill} command, and @command{bash} at least, +as @code{trap foo 0} and @code{trap foo EXIT} are equivalent. + +@noindent +The following signal names and numbers are supported +on all POSIX compliant systems: @table @samp @item HUP diff --git a/src/kill.c b/src/kill.c index 8b9a2650f..314855653 100644 --- a/src/kill.c +++ b/src/kill.c @@ -120,7 +120,7 @@ list_signals (bool table, char *const *argv) num_width++; /* Compute the maximum width of a signal name. */ - for (signum = 1; signum <= SIGNUM_BOUND; signum++) + for (signum = 0; signum <= SIGNUM_BOUND; signum++) if (sig2str (signum, signame) == 0) { idx_t len = strlen (signame); @@ -142,7 +142,7 @@ list_signals (bool table, char *const *argv) } } else - for (signum = 1; signum <= SIGNUM_BOUND; signum++) + for (signum = 0; signum <= SIGNUM_BOUND; signum++) if (sig2str (signum, signame) == 0) print_table_row (num_width, signum, name_width, signame); } @@ -165,7 +165,7 @@ list_signals (bool table, char *const *argv) printf ("%d\n", signum); } else - for (signum = 1; signum <= SIGNUM_BOUND; signum++) + for (signum = 0; signum <= SIGNUM_BOUND; signum++) if (sig2str (signum, signame) == 0) puts (signame); } diff --git a/tests/misc/kill.sh b/tests/misc/kill.sh index 82812eada..ed4773f65 100755 --- a/tests/misc/kill.sh +++ b/tests/misc/kill.sh @@ -68,4 +68,7 @@ test -n "$SIG_SEQ" || framework_failure_ env kill -l -- $SIG_SEQ || fail=1 env kill -t -- $SIG_SEQ || fail=1 +# Verify first signal number listed is 0 +test $(env kill -l $(env kill -l | head -n1)) = 0 || fail=1 + Exit $fail -- 2.11.4.GIT