From: William Lallemand Date: Tue, 20 Jun 2017 09:20:23 +0000 (+0200) Subject: MINOR: mworker: don't copy -x argument anymore in copy_argv() X-Git-Tag: v1.8-dev3~282 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bf6d6291614537530958282da6a7a66c03bf5fe;p=thirdparty%2Fhaproxy.git MINOR: mworker: don't copy -x argument anymore in copy_argv() 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. --- diff --git a/src/haproxy.c b/src/haproxy.c index 1eabb55294..cdb6066b5a 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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 */ - 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; }