|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
diff -Naur a/misc-utils/kill.1.adoc b/misc-utils/kill.1.adoc
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
--- a/misc-utils/kill.1.adoc 2022-02-13 23:49:01.403480088 -0800
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+++ b/misc-utils/kill.1.adoc 2022-12-07 16:37:26.037765934 -0800
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -62,6 +62,8 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
Do not restrict the command-name-to-PID conversion to processes with the same UID as the present process.
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
*-p*, *--pid*::
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
Only print the process ID (PID) of the named processes, do not send any signals.
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+*-r*, *--require-handler*::
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+Do not send the signal if it is not caught in userspace by the signalled process.
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
*--verbose*::
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
Print PID(s) that will be signaled with *kill* along with the signal.
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
*-q*, *--queue* _value_::
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
diff -Naur a/misc-utils/kill.c b/misc-utils/kill.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
--- a/misc-utils/kill.c 2022-02-13 23:49:01.403480088 -0800
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+++ b/misc-utils/kill.c 2022-12-07 16:38:05.231013950 -0800
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -93,6 +93,7 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
check_all:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
do_kill:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
do_pid:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ require_handler:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
use_sigval:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
#ifdef UL_HAVE_PIDFD
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
timeout:1,
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -210,6 +211,7 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
fputs(_(" -p, --pid print pids without signaling them\n"), out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
fputs(_(" -l, --list[=<signal>] list signal names, or convert a signal number to a name\n"), out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
fputs(_(" -L, --table list signal names and numbers\n"), out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ fputs(_(" -r, --require-handler do not send signal if signal handler is not present\n"), out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
fputs(_(" --verbose print pids that will be signaled\n"), out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
fputs(USAGE_SEPARATOR, out);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -300,6 +302,10 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
print_all_signals(stdout, 1);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
exit(EXIT_SUCCESS);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (!strcmp(arg, "-r") || !strcmp(arg, "--require-handler")) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ ctl->require_handler = 1;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ continue;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
if (!strcmp(arg, "-p") || !strcmp(arg, "--pid")) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
ctl->do_pid = 1;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
if (ctl->do_kill)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -446,6 +452,32 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
return rc;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+static int check_signal_handler(const struct kill_control *ctl)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+{
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ uintmax_t sigcgt = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ int rc = 0, has_hnd = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ struct path_cxt *pc;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (!ctl->require_handler)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ return 1;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ pc = ul_new_procfs_path(ctl->pid, NULL);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (!pc)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ return -ENOMEM;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ rc = procfs_process_get_stat_nth(pc, 34, &sigcgt);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (rc)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ return -EINVAL;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ ul_unref_path(pc);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ has_hnd = ((1UL << (ctl->numsig - 1)) & sigcgt) != 0;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (ctl->verbose && !has_hnd)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ printf(_("not signalling pid %d, it has no userspace handler for signal %d\n"), ctl->pid, ctl->numsig);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ return has_hnd;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
int main(int argc, char **argv)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
{
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
struct kill_control ctl = { .numsig = SIGTERM };
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -468,6 +500,8 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
errno = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
ctl.pid = strtol(ctl.arg, &ep, 10);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
if (errno == 0 && ep && *ep == '\0' && ctl.arg < ep) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (check_signal_handler(&ctl) <= 0)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ continue;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
if (kill_verbose(&ctl) != 0)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
nerrs++;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
ct++;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
@@ -482,6 +516,8 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
proc_processes_filter_by_name(ps, ctl.arg);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
while (proc_next_pid(ps, &ctl.pid) == 0) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ if (check_signal_handler(&ctl) <= 0)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
+ continue;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
if (kill_verbose(&ctl) != 0)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
nerrs++;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
29d451 |
ct++;
|