Debian Codegraph @

debian/patches/kill_negative_pids

raw
1 Description: kill: Correctly parse negative pids
2 kill would only correctly parse single digit negative pids because
3 it was using the optopt which is a single character, it now uses the
4 entire argument.
5 Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/bfbaf43acade8c9de38737e87f4fc535991c8359
6 Applied-Upstream: 4.0.5
7 Reviewed-by: Craig Small <[email protected]>
8 Last-Update: 2025-04-13
9 ---
10 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
11 --- a/src/kill.c
12 +++ b/src/kill.c
13 @@ -138,7 +138,8 @@
14 } else {
15 /* Special case for signal digit negative
16 * PIDs */
17 - pid = (long)('0' - optopt);
18 + pid = strtol_or_err(argv[optind], _("failed to parse argument"));
19 +
20 if (!execute_kill((pid_t) pid, signo, use_sigqueue, sigval))
21 exitvalue = EXIT_FAILURE;
22 exit(exitvalue);
23 --- a/man/kill.1
24 +++ b/man/kill.1
25 @@ -72,6 +72,12 @@
26 Your shell (command line interpreter) may have a built-in kill
27 command. You may need to run the command described here as /bin/kill
28 to solve the conflict.
29 +.PP
30 +If you use negative PID values, you will need to specify a signal as well so that
31 +.B kill
32 +knows if the option is for the PID or the signal number. For example, issuing
33 +the command with the single option \fB\-9\fR it is not clear if you
34 +mean signal 9 (SIGKILL) or process group 9.
35 .SH EXAMPLES
36 .TP
37 .B kill \-9 \-1
38 @@ -85,6 +91,10 @@
39 .TP
40 .B kill 123 543 2341 3453
41 Send the default signal, SIGTERM, to all those processes.
42 +.TP
43 +.B kill -SIGTERM -123
44 +Send the signal SIGTERM to process group 123. The signal name or number is
45 +required if specifying process groups with a negative PID.
46 .SH "SEE ALSO"
47 .BR kill (2),
48 .BR killall (1),