env,kill,timeout: support unnamed signals
commitb8d1b00e21a86270fbbe5903a41319894db266df
authorGrisha Levit <grishalevit@gmail.com>
Thu, 25 Jan 2024 19:52:50 +0000 (25 14:52 -0500)
committerPádraig Brady <P@draigBrady.com>
Wed, 13 Mar 2024 16:15:35 +0000 (13 16:15 +0000)
tree5af921c0aa4ea9306534a919380bac2907240778
parentc7f422940a3d12cd338e3a13d5adc9dbbf45e145
env,kill,timeout: support unnamed signals

Some signals with values less that the max signal number for the system
do not have defined names.  For example, currently on amd64 Linux,
signals 32 and 33 do not have defined names, and Android has a wider
gap of undefined names where it reserves some realtime signals.

Previously the signal listing in env ended up reusing the name
of the last printed valid signal (the repeated HUP below):

    $ env --list-signal-handling true
    HUP        ( 1): IGNORE
    HUP        (32): BLOCK
    HUP        (38): IGNORE

..and the corresponding signal numbers were rejected as operands for the
env, kill, and timeout commands.

This patch removes the requirement that sig2str returns 0 for a signal
number associated with an operand.  This allows unnamed signals to be in
the sets `env' attempts to manipulate when a --*-signal option is used
with no argument, and kill(1) and timeout(1) to send such unnamed
signals.

* src/operand2sig.c (operand2sig): Drop signame argument, accept all
signal numbers <= SIGNUM_BOUND.  All callers updated.
* src/env.c (parse_signal_action_params, reset_signal_handlers)
(parse_block_signal_params, set_signal_proc_mask)
(list_signal_handling): Accept all signal numbers <= SIGNUM_BOUND,
use SIG%d for printing if necessary.
* src/kill.c (list_signals, main): Likewise.
(send_signals): Check errno from kill(3) for bad signo.
* src/timeout.c (main): Update operand2sig call.
* tests/misc/kill.sh: Test listing all signal numbers.
* NEWS: Mention the improvement.
NEWS
src/env.c
src/kill.c
src/operand2sig.c
src/operand2sig.h
src/timeout.c
tests/misc/kill.sh