svc: fix a case where with more than option, getopt() state is not reset
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 4 Aug 2017 23:38:55 +0000 (01:38 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 4 Aug 2017 23:40:12 +0000 (01:40 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
runit/sv.c

index faa31d4faee944e76bf906fd31dad81c60c0f622..b39815613c0811bc1359fbe20c297899dc8ea6d9 100644 (file)
@@ -718,15 +718,16 @@ int svc_main(int argc UNUSED_PARAM, char **argv)
        argv[1] = command;
        command[1] = '\0';
 
-       /* getopt32() was already called:
-        * reset the libc getopt() function, which keeps internal state.
-        */
-       GETOPT_RESET();
-
        do {
                if (opts & 1) {
                        int r;
+
                        command[0] = *optstring;
+
+                       /* getopt() was already called by getopt32():
+                        * reset the libc getopt() function's internal state.
+                        */
+                       GETOPT_RESET();
                        r = sv(argv);
                        if (r)
                                return 1;