pkill: fix signal spec regression

Commig a5d9c40262 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>
This commit is contained in:
Sami Kerola 2012-06-24 13:30:22 +02:00
parent cba9bdbc16
commit d45456fb8a

23
pgrep.c
View File

@ -563,18 +563,19 @@ static struct el * select_procs (int *num)
int signal_option(int *argc, char **argv) int signal_option(int *argc, char **argv)
{ {
int sig; int sig;
int i = 1; int i;
if (*argc > 2 && argv[1][0] == '-') { for (i = 1; i < *argc; i++) {
sig = signal_name_to_number(argv[i] + 1); if (argv[i][0] == '-') {
if (sig == -1 && isdigit(argv[1][1])) sig = signal_name_to_number(argv[i] + 1);
sig = atoi(argv[1] + 1); if (sig == -1 && isdigit(argv[i][1]))
if (-1 < sig) { sig = atoi(argv[i] + 1);
memmove(argv + i, argv + i + 1, if (-1 < sig) {
sizeof(char *) * (*argc - i)); memmove(argv + i, argv + i + 1,
(*argc)--; sizeof(char *) * (*argc - i));
return sig; (*argc)--;
return sig;
}
} }
i++;
} }
return -1; return -1;
} }