]> granicus.if.org Git - procps-ng/commitdiff
kill: a better option parser
authorCraig Small <csmall@enc.com.au>
Tue, 7 Feb 2017 11:37:36 +0000 (22:37 +1100)
committerCraig Small <csmall@enc.com.au>
Tue, 7 Feb 2017 11:37:36 +0000 (22:37 +1100)
The previous commit would not work in newlib. Further investigation
found a better way of parsing this extra option using optind

References:
 commit 536cea324b121f54744369425332c256aa84a181

skill.c

diff --git a/skill.c b/skill.c
index 5d233c255002dc140b2220e2f993c8ecf0b52ad8..14e5b58408a77707435a6283ac94dd425a062a49 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -422,7 +422,6 @@ static void __attribute__ ((__noreturn__))
        int loop = 1;
        long pid;
        int exitvalue = EXIT_SUCCESS;
-    int optindex;
     char *sig_option;
 
        static const struct option longopts[] = {
@@ -447,14 +446,14 @@ static void __attribute__ ((__noreturn__))
                signo = SIGTERM;
 
        opterr=0; /* suppress errors on -123 */
-       while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, &optindex)) != -1)
+       while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
                switch (i) {
                case 'l':
             sig_option = NULL;
             if (optarg) {
                 sig_option = optarg;
-            } else if (argv[optindex+1] != NULL && argv[optindex+1][0] != '-') {
-                sig_option = argv[optindex+1];
+            } else if (argv[optind] != NULL && argv[optind][0] != '-') {
+                sig_option = argv[optind];
             }
                        if (sig_option) {
                                char *s;