]> granicus.if.org Git - procps-ng/commitdiff
kill -PID fixed
authorCraig Small <csmall@enc.com.au>
Tue, 2 Oct 2012 11:56:38 +0000 (21:56 +1000)
committerCraig Small <csmall@enc.com.au>
Tue, 2 Oct 2012 11:56:38 +0000 (21:56 +1000)
Bug-Debian: http://bugs.debian.org/688731

kill would not permit negative PIDs and thought they were options. kill
now explicitly checks for unknown options and if they are numeric
assumes they are negative PIDs.  The first negative PID stops any
further option processing.

Signed-off-by: Craig Small <csmall@enc.com.au>
skill.c

diff --git a/skill.c b/skill.c
index 94bf9c93ae0969bd88e07b4c4678be48ff463248..a1f89e0a9619d38b81870bac73206f5f96b940e8 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -363,6 +363,7 @@ static void __attribute__ ((__noreturn__))
 {
        int signo, i;
        int sigopt = 0;
+       int loop = 1;
        long pid;
        int exitvalue = EXIT_SUCCESS;
 
@@ -389,7 +390,8 @@ static void __attribute__ ((__noreturn__))
        else
                sigopt++;
 
-       while ((i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
+       opterr=0; /* suppress errors on -123 */
+       while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
                switch (i) {
                case 'l':
                        if (optarg) {
@@ -416,6 +418,13 @@ static void __attribute__ ((__noreturn__))
                case 'V':
                        display_kill_version();
                        exit(EXIT_SUCCESS);
+               case '?':
+                       if (!isdigit(optopt)) {
+                               xwarnx(_("invalid argument %c"), optopt);
+                               kill_usage(stderr);
+                       }
+                       loop=0;
+                       break;
                default:
                        kill_usage(stderr);
                }