From 5019b50b6dd568fcfce070ea926ab78cb2cef312 Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Dec 08 2022 00:24:35 +0000 Subject: Backport upstream PR to require signal handler in kill --- diff --git a/SOURCES/1004-kill-support-mandating-userspace-signal-handler.patch b/SOURCES/1004-kill-support-mandating-userspace-signal-handler.patch new file mode 100644 index 0000000..3c0684f --- /dev/null +++ b/SOURCES/1004-kill-support-mandating-userspace-signal-handler.patch @@ -0,0 +1,93 @@ +diff -Naur a/misc-utils/kill.1 b/misc-utils/kill.1 +--- a/misc-utils/kill.1 2018-07-11 06:34:54.235003686 -0700 ++++ b/misc-utils/kill.1 2022-12-07 16:19:17.911880263 -0800 +@@ -99,6 +99,8 @@ + \fB\-p\fR, \fB\-\-pid\fR + Only print the process ID (PID) of the named processes, do not send any + signals. ++\fB\-r\fR, \fB\-\-require\-handler\fR ++Do not send the signal if it is not caught in userspace by the signalled process. + .TP + \fB\-\-verbose\fR + Print PID(s) that will be signaled with kill along with the signal. +diff -Naur a/misc-utils/kill.c b/misc-utils/kill.c +--- a/misc-utils/kill.c 2018-06-04 00:57:02.809445758 -0700 ++++ b/misc-utils/kill.c 2022-12-07 16:21:16.372629866 -0800 +@@ -79,6 +79,7 @@ + check_all:1, + do_kill:1, + do_pid:1, ++ require_handler:1, + use_sigval:1, + verbose:1; + }; +@@ -188,6 +189,7 @@ + fputs(_(" -p, --pid print pids without signaling them\n"), out); + fputs(_(" -l, --list[=] list signal names, or convert a signal number to a name\n"), out); + fputs(_(" -L, --table list signal names and numbers\n"), out); ++ fputs(_(" -r, --require-handler do not send signal if signal handler is not present\n"), out); + fputs(_(" --verbose print pids that will be signaled\n"), out); + + fputs(USAGE_SEPARATOR, out); +@@ -254,6 +256,10 @@ + print_all_signals(stdout, 1); + exit(EXIT_SUCCESS); + } ++ if (!strcmp(arg, "-r") || !strcmp(arg, "--require-handler")) { ++ ctl->require_handler = 1; ++ continue; ++ } + if (!strcmp(arg, "-p") || !strcmp(arg, "--pid")) { + ctl->do_pid = 1; + if (ctl->do_kill) +@@ -335,6 +341,32 @@ + return rc; + } + ++static int check_signal_handler(const struct kill_control *ctl) ++{ ++ uintmax_t sigcgt = 0; ++ int rc = 0, has_hnd = 0; ++ struct path_cxt *pc; ++ ++ if (!ctl->require_handler) ++ return 1; ++ ++ pc = ul_new_procfs_path(ctl->pid, NULL); ++ if (!pc) ++ return -ENOMEM; ++ ++ rc = procfs_process_get_stat_nth(pc, 34, &sigcgt); ++ if (rc) ++ return -EINVAL; ++ ++ ul_unref_path(pc); ++ ++ has_hnd = ((1UL << (ctl->numsig - 1)) & sigcgt) != 0; ++ if (ctl->verbose && !has_hnd) ++ printf(_("not signalling pid %d, it has no userspace handler for signal %d\n"), ctl->pid, ctl->numsig); ++ ++ return has_hnd; ++} ++ + int main(int argc, char **argv) + { + struct kill_control ctl = { .numsig = SIGTERM }; +@@ -354,6 +386,8 @@ + errno = 0; + ctl.pid = strtol(ctl.arg, &ep, 10); + if (errno == 0 && ep && *ep == '\0' && ctl.arg < ep) { ++ if (check_signal_handler(&ctl) <= 0) ++ continue; + if (kill_verbose(&ctl) != 0) + nerrs++; + ct++; +@@ -368,6 +402,8 @@ + + proc_processes_filter_by_name(ps, ctl.arg); + while (proc_next_pid(ps, &ctl.pid) == 0) { ++ if (check_signal_handler(&ctl) <= 0) ++ continue; + if (kill_verbose(&ctl) != 0) + nerrs++; + ct++; diff --git a/SPECS/util-linux.spec b/SPECS/util-linux.spec index a4c0fa1..44e20f1 100644 --- a/SPECS/util-linux.spec +++ b/SPECS/util-linux.spec @@ -273,6 +273,7 @@ Patch1000: 1000-setpriv-add-reset-env.patch Patch1001: 1001-losetup-avoid-infinite-busy-loop.patch Patch1002: 1002-losetup-increase-limit-of-setup-attempts.patch Patch1003: 1003-lib-loopdev-perform-retry-on-EAGAIN.patch +Patch1004: 1004-kill-support-mandating-userspace-signal-handler.patch %description The util-linux package contains a large variety of low-level system @@ -1129,6 +1130,8 @@ fi %changelog * Wed Dec 07 2022 Davide Cavalca 2.32.1-39.1 - Merge upsteam changes in Hyperscale +- Backport https://github.com/util-linux/util-linux/pull/1865 which adds + support to kill for mandating the precence of a userspace signal handler * Wed Nov 16 2022 Karel Zak 2.32.1-39 - fix #2141969 - Add --cont-clock feature for libuuid and uuidd