]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: don't copy -x argument anymore in copy_argv()
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 20 Jun 2017 09:20:23 +0000 (11:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Jun 2017 12:43:28 +0000 (14:43 +0200)
Don't copy the -x argument anymore in copy_argv() since it's already
allocated in mworker_reload().

Make the copy_argv() more consistent when used with multiple arguments
to strip.

It prevents multiple -x on reload, which is not supported.

src/haproxy.c

index 1eabb552949a5f975d7a90ddb2245d4c9056ae9e..cdb6066b5a9d42a2d5b916ccdc8eb7d65d8aedc6 100644 (file)
@@ -596,23 +596,12 @@ static void mworker_reload()
        }
        next_argv[next_argc] = NULL;
 
-       /* if -x was used, try to update the stat socket if not available anymore */
+       /* add the -x option with the stat socket */
        if (cur_unixsocket) {
 
-               if (old_unixsocket) {
-
-                       /* look for -x <path> */
-                       for (j = 0; next_argv[j]; j++) {
-                               if (!strcmp(next_argv[j], "-x"))
-                                       next_argv[j + 1] = (char *)cur_unixsocket;
-                       }
-               } else {
-                       /* if -x is not specified but we know the socket, add -x with it */
-                       next_argv[next_argc++] = "-x";
-                       next_argv[next_argc++] = (char *)cur_unixsocket;
-                       next_argv[next_argc++] = NULL;
-
-               }
+               next_argv[next_argc++] = "-x";
+               next_argv[next_argc++] = (char *)cur_unixsocket;
+               next_argv[next_argc++] = NULL;
        }
 
        deinit(); /* we don't want to leak FD there */
@@ -1101,7 +1090,7 @@ out:
 static char **copy_argv(int argc, char **argv)
 {
        char **newargv;
-       int i, j;
+       int i = 0, j = 0;
 
        newargv = calloc(argc + 2, sizeof(char *));
        if (newargv == NULL) {
@@ -1109,19 +1098,20 @@ static char **copy_argv(int argc, char **argv)
                return NULL;
        }
 
-       for (i = 0, j = 0; i < argc; i++, j++) {
-               char *flag = *(argv + i) + 1;
-
-               /* -sf or -st */
-               if (*flag == 's' && (flag[1] == 'f' || flag[1] == 't')) {
-                       /* list of pids to finish ('f') or terminate ('t') */
+       while (i < argc) {
+               /* -sf or -st or -x */
+               if ((argv[i][1] == 's' && (argv[i][2] == 'f' || argv[i][2] == 't')) || argv[i][1] == 'x' ) {
+                       /* list of pids to finish ('f') or terminate ('t') or unix socket (-x) */
                        i++;
                        while (i < argc && argv[i][0] != '-') {
                                i++;
                        }
+                       continue;
                }
-               newargv[j] = argv[i];
+
+               newargv[j++] = argv[i++];
        }
+
        return newargv;
 }