#2 Backport upstream PR to require signal handler in kill
Opened 2 years ago by dcavalca. Modified 2 years ago
rpms/ dcavalca/util-linux c9s-sig-hyperscale  into  c9s-sig-hyperscale

@@ -0,0 +1,93 @@ 

+ diff -Naur a/misc-utils/kill.1.adoc b/misc-utils/kill.1.adoc

+ --- a/misc-utils/kill.1.adoc	2022-02-13 23:49:01.403480088 -0800

+ +++ b/misc-utils/kill.1.adoc	2022-12-07 16:37:26.037765934 -0800

+ @@ -62,6 +62,8 @@

+  Do not restrict the command-name-to-PID conversion to processes with the same UID as the present process.

+  *-p*, *--pid*::

+  Only print the process ID (PID) of the named processes, do not send any signals.

+ +*-r*, *--require-handler*::

+ +Do not send the signal if it is not caught in userspace by the signalled process.

+  *--verbose*::

+  Print PID(s) that will be signaled with *kill* along with the signal.

+  *-q*, *--queue* _value_::

+ diff -Naur a/misc-utils/kill.c b/misc-utils/kill.c

+ --- a/misc-utils/kill.c	2022-02-13 23:49:01.403480088 -0800

+ +++ b/misc-utils/kill.c	2022-12-07 16:38:05.231013950 -0800

+ @@ -93,6 +93,7 @@

+  		check_all:1,

+  		do_kill:1,

+  		do_pid:1,

+ +		require_handler:1,

+  		use_sigval:1,

+  #ifdef UL_HAVE_PIDFD

+  		timeout:1,

+ @@ -210,6 +211,7 @@

+  	fputs(_(" -p, --pid              print pids without signaling them\n"), out);

+  	fputs(_(" -l, --list[=<signal>]  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);

+ @@ -300,6 +302,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)

+ @@ -446,6 +452,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 };

+ @@ -468,6 +500,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++;

+ @@ -482,6 +516,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++;

file modified
+10 -1
@@ -2,7 +2,7 @@ 

  Summary: A collection of basic system utilities

  Name: util-linux

  Version: 2.37.4

- Release: 9%{?dist}

+ Release: 9.1%{?dist}

  License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain

  URL: http://en.wikipedia.org/wiki/Util-linux

  
@@ -150,6 +150,11 @@ 

  # 2094216 - lslogins reports incorrect "Password is locked" status

  Patch36: 0036-lslogins-support-more-password-methods.patch

  

+ ### Hyperscale patches

+ #

+ # kill: Support mandating the presence of a userspace signal handler

+ Patch1000: 1000-kill-support-mandating-userspace-signal-handler.patch

+ 

  

  %description

  The util-linux package contains a large variety of low-level system
@@ -984,6 +989,10 @@ 

  %{_libdir}/python*/site-packages/libmount/

  

  %changelog

+ * Wed Dec 07 2022 Davide Cavalca <dcavalca@centosproject.org> 2.37.4-9.1

+ - 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 Aug 24 2022 Karel Zak <kzak@redhat.com> 2.37.4-9

  - improve lslogins pasword validator (related #2094216)

  

Backport https://github.com/util-linux/util-linux/pull/1865 which adds support to kill for mandating the precence of a userspace signal handler

Similarly to #1, this one fails to build with

/usr/bin/ld: /tmp/ccdgtpMG.ltrans0.ltrans.o: in function `check_signal_handler':
/builddir/build/BUILD/util-linux-2.37.4/misc-utils/kill.c:464: undefined reference to `ul_new_procfs_path'
/usr/bin/ld: /builddir/build/BUILD/util-linux-2.37.4/misc-utils/kill.c:468: undefined reference to `procfs_process_get_stat_nth'

cc @cdown