skill: fix command line with signal, again

Application of master patch d1d2ccf

Original by Filipe Brandenburger <filbranden@google.com>

Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
Craig Small 2016-04-11 20:59:48 +10:00
parent 1f8e41d019
commit 6586f9f9ce
3 changed files with 8 additions and 14 deletions

6
kill.c
View File

@ -50,7 +50,7 @@ static void __attribute__ ((__noreturn__)) print_usage(FILE * out)
int main(int argc, char **argv)
{
int signo, i, sigopt=0, loop=1;
int signo, i, loop=1;
long pid;
int exitvalue = EXIT_SUCCESS;
@ -75,8 +75,6 @@ int main(int argc, char **argv)
signo = skill_sig_option(&argc, argv);
if (signo < 0)
signo = SIGTERM;
else
sigopt++;
opterr=0; /* suppress errors on -123 */
while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
@ -124,7 +122,7 @@ int main(int argc, char **argv)
print_usage(stderr);
}
argc -= optind + sigopt;
argc -= optind;
argv += optind;
for (i = 0; i < argc; i++) {

View File

@ -200,17 +200,15 @@ const char *signal_number_to_name(int signo)
int skill_sig_option(int *argc, char **argv)
{
int i, nargs = *argc;
int i;
int signo = -1;
for (i = 1; i < nargs; i++) {
for (i = 1; i < *argc; i++) {
if (argv[i][0] == '-') {
signo = signal_name_to_number(argv[i] + 1);
if (-1 < signo) {
if (nargs - i) {
nargs--;
memmove(argv + i, argv + i + 1,
sizeof(char *) * (nargs - i));
}
memmove(argv + i, argv + i + 1,
sizeof(char *) * (*argc - i));
(*argc)--;
return signo;
}
}

View File

@ -418,10 +418,8 @@ static void parse_options(int argc,
prino = snice_prio_option(&argc, argv);
else if (program == PROG_SKILL) {
signo = skill_sig_option(&argc, argv);
if (-1 < signo) {
if (-1 < signo)
sig_or_pri = signo;
argc -= 1;
}
}
pid_count = 0;