kill: add '--' option to separate options from arguments
authorRon Yorston <rmy@pobox.com>
Sun, 27 Aug 2017 07:25:18 +0000 (08:25 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 28 Aug 2017 12:03:13 +0000 (14:03 +0200)
Using a negative pid to send TERM to a process group results in an
obscure error:

   $ ./busybox kill -12345
   kill: bad signal name '12345'

This is intended. Manpage says:
ARGUMENTS
       pid    Each pid can be one of four things:
...
              -n     where n is larger than 1.  All processes in process group
                     n are signaled.  When an argument of  the  form  '-n'  is
                     given,  and it is meant to denote a process group, either
                     a signal must be specified first, or the argument must be
                     preceded  by a '--' option, otherwise it will be taken as
                     the signal to send.

However, we did not support "--". Add this capability to BusyBox.

function                                             old     new   delta
kill_main                                            993     999      +6

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
procps/kill.c

index 0ddae2f70811dc74930168cb26aba337921e03b2..24cc903fcd07939f8cea26812d83c1816330ede9 100644 (file)
@@ -184,6 +184,10 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
        if (is_killall5 && arg[0] == 'o')
                goto do_it_now;
 
+       /* "--" separates options from args. Testcase: "kill -- -123" */
+       if (!is_killall5 && arg[0] == '-' && arg[1] == '\0')
+               goto do_it_sooner;
+
        if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
                arg = *++argv;
        } /* else it must be -SIG */
@@ -192,6 +196,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
                bb_error_msg("bad signal name '%s'", arg);
                return EXIT_FAILURE;
        }
+ do_it_sooner:
        arg = *++argv;
 
  do_it_now: