]> granicus.if.org Git - procps-ng/commitdiff
pkill: fix signal spec regression
authorSami Kerola <kerolasa@iki.fi>
Sun, 24 Jun 2012 11:30:22 +0000 (13:30 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 24 Jun 2012 11:30:22 +0000 (13:30 +0200)
Commig a5d9c40262c2f5f917d5f27c5f052bdbe7066ac1 caused signal spec,
again, to be required as first option; for example

pkill -3 <program> # worked
pkill <program> -3 # did not

This commit fixes the regression, without breaking option -u <numeric>
argument, assuming no-one is using negative numeric UID specifications
with space after -u && the argument.  IMHO such use case is rare enough
to be broken.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pgrep.c

diff --git a/pgrep.c b/pgrep.c
index 3377175f27a586a76080da9df4668d20b8e96adf..3a4b34512e54f8876fa2dadad3969af39f95f608 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -563,18 +563,19 @@ static struct el * select_procs (int *num)
 int signal_option(int *argc, char **argv)
 {
        int sig;
-       int i = 1;
-       if (*argc > 2 && argv[1][0] == '-') {
-               sig = signal_name_to_number(argv[i] + 1);
-               if (sig == -1 && isdigit(argv[1][1]))
-                       sig = atoi(argv[1] + 1);
-               if (-1 < sig) {
-                       memmove(argv + i, argv + i + 1,
-                               sizeof(char *) * (*argc - i));
-                       (*argc)--;
-                       return sig;
+       int i;
+       for (i = 1; i < *argc; i++) {
+               if (argv[i][0] == '-') {
+                       sig = signal_name_to_number(argv[i] + 1);
+                       if (sig == -1 && isdigit(argv[i][1]))
+                               sig = atoi(argv[i] + 1);
+                       if (-1 < sig) {
+                               memmove(argv + i, argv + i + 1,
+                                       sizeof(char *) * (*argc - i));
+                               (*argc)--;
+                               return sig;
+                       }
                }
-               i++;
        }
        return -1;
 }