From 6586f9f9ce1e65ec3c389dbe733e9780753d693b Mon Sep 17 00:00:00 2001 From: Craig Small Date: Mon, 11 Apr 2016 20:59:48 +1000 Subject: [PATCH] skill: fix command line with signal, again Application of master patch d1d2ccf Original by Filipe Brandenburger Signed-off-by: Craig Small --- kill.c | 6 ++---- lib/signals.c | 12 +++++------- skill.c | 4 +--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/kill.c b/kill.c index ce1e3c29..65bb19de 100644 --- a/kill.c +++ b/kill.c @@ -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++) { diff --git a/lib/signals.c b/lib/signals.c index cff3966c..d9b5b9b4 100644 --- a/lib/signals.c +++ b/lib/signals.c @@ -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; } } diff --git a/skill.c b/skill.c index ebfe4b85..dbd4600d 100644 --- a/skill.c +++ b/skill.c @@ -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;