1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-14 19:32:10 +02:00
Files
coreutils/tests/misc/kill.sh
Grisha Levit b8d1b00e21 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.
2024-03-13 16:15:35 +00:00

72 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# Validate kill operation
# Copyright (C) 2015-2024 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ kill seq
# params required
returns_ 1 env kill || fail=1
returns_ 1 env kill -TERM || fail=1
# Invalid combinations
returns_ 1 env kill -l -l || fail=1
returns_ 1 env kill -l -t || fail=1
returns_ 1 env kill -l -s 1 || fail=1
returns_ 1 env kill -t -s 1 || fail=1
# signal sending
returns_ 1 env kill -0 no_pid || fail=1
env kill -0 $$ || fail=1
env kill -s0 $$ || fail=1
env kill -n0 $$ || fail=1 # bash compat
env kill -CONT $$ || fail=1
env kill -Cont $$ || fail=1
returns_ 1 env kill -cont $$ || fail=1
env kill -0 -1 || fail=1 # to group
# table listing
env kill -l || fail=1
env kill -t || fail=1
env kill -L || fail=1 # bash compat
env kill -t TERM HUP || fail=1
# Verify (multi) name to signal number and vice versa
SIGTERM=$(env kill -l HUP TERM | tail -n1) || fail=1
test $(env kill -l "$SIGTERM") = TERM || fail=1
# Verify we only consider the lower "signal" bits,
# to support ksh which just adds 256 to the signal value
STD_TERM_STATUS=$(expr "$SIGTERM" + 128)
KSH_TERM_STATUS=$(expr "$SIGTERM" + 256)
test $(env kill -l $STD_TERM_STATUS $KSH_TERM_STATUS | uniq) = TERM || fail=1
# Verify invalid signal spec is diagnosed
returns_ 1 env kill -l -1 || fail=1
returns_ 1 env kill -l -1 0 || fail=1
returns_ 1 env kill -l INVALID TERM || fail=1
# Verify all signal numbers can be listed
SIG_LAST_STR=$(env kill -l | tail -n1) || framework_failure_
SIG_LAST_NUM=$(env kill -l -- "$SIG_LAST_STR") || framework_failure_
SIG_SEQ=$(env seq -- 0 "$SIG_LAST_NUM") || framework_failure_
test -n "$SIG_SEQ" || framework_failure_
env kill -l -- $SIG_SEQ || fail=1
env kill -t -- $SIG_SEQ || fail=1
Exit $fail