Subject: bug#68708: [PATCH] env,kill: Handle unnamed signals

From: Pádraig Brady <[email-masked]>
Date: Thu, 25 Jan 2024 14:50:07 +0000

On 24/01/2024 20:40, Grisha Levit wrote:
> Android reserves [1] some realtime signals and redefines [2] SIGRTMIN,
> leaving a gap between the signals that have SIG* constants defined in
> signal.h and SIGRTMIN.
> 
> When passed such a signal number, gnulib sig2str returns -1 and leaves
> its signame argument unchanged.
> 
> The signal listing in env ends up reusing the name of the last printed
> valid signal:
> 
>      $ env --list-signal-handling true
>      HUP        ( 1): IGNORE
>      HUP        (32): BLOCK
>      HUP        (38): IGNORE
> 
> ..and the corresponding signal numbers are 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, and allows unnamed signals to be in
> the sets `env' attempts to manipulate when a --*-signal option is used
> with no argument.
> 
> This does leave the possibility of numbers lower than SIGNUM_BOUND that
> are not valid signals, but I'm not sure that's really a problem for the
> existing code paths (if it is, adding checks for sigset_t manipulations
> would probably be enough).
> 
> To be on the safe side, added a check to report kill(3) EINVAL as a bad
> signo (rather than always blaming the pid).
> 
> This does not change the default list printed with `kill -l'.  When a
> name is to be printed, the signal number associated with an unnamed
> signal is used.
> 
> [1]: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/platform/bionic/reserved_signals.h
> [2]: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/signal.h;l=51
> 

This mostly looks good, except:

- No need to clear the errno before kill(3).
- Better to use SIG%d rather than the bare %d for signal _names_, as we already parse this format

thanks!
Pádraig