pgrep: allow signal definition to be anywhere in command line
I as user often try to pkill something, notice that program did not die and pkill again with signal -9. Before this commit previous one could not add signal at the end of command line, as the signal definition had to be first argument, which was annoying. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
e756a3db40
commit
a1f8166642
38
pgrep.c
38
pgrep.c
@ -553,6 +553,24 @@ static struct el * select_procs (int *num)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int signal_option(int *argc, char **argv)
|
||||||
|
{
|
||||||
|
int sig;
|
||||||
|
int i = 1;
|
||||||
|
while (i < *argc) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_opts (int argc, char **argv)
|
static void parse_opts (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -589,21 +607,11 @@ static void parse_opts (int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (strstr (program_invocation_short_name, "pkill")) {
|
if (strstr (program_invocation_short_name, "pkill")) {
|
||||||
i_am_pkill = 1;
|
int sig;
|
||||||
/* Look for a signal name or number as first argument */
|
i_am_pkill = 1;
|
||||||
if (argc > 1 && argv[1][0] == '-') {
|
sig = signal_option(&argc, argv);
|
||||||
int sig;
|
if (-1 < sig)
|
||||||
sig = signal_name_to_number (argv[1] + 1);
|
opt_signal = sig;
|
||||||
if (sig == -1 && isdigit (argv[1][1]))
|
|
||||||
sig = atoi (argv[1] + 1);
|
|
||||||
if (sig != -1) {
|
|
||||||
int i;
|
|
||||||
for (i = 2; i < argc; i++)
|
|
||||||
argv[i-1] = argv[i];
|
|
||||||
--argc;
|
|
||||||
opt_signal = sig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* These options are for pkill only */
|
/* These options are for pkill only */
|
||||||
strcat (opts, "e");
|
strcat (opts, "e");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user