From a088d316b71dd71ec86e287d59322f9245e3b36b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 8 Oct 2015 11:58:48 +0200 Subject: [PATCH] MEDIUM: init: support a list of files on the command line HAProxy could already support being passed a file list on the command line, by passing multiple times "-f" followed by a file name. People have been complaining that it made it hard to pass file lists from init scripts. This patch introduces an end of arguments using the common "--" tag, after which only file names may appear. These files are then added to the existing list of other files specified using -f and are loaded in their declaration order. Thus it becomes possible to do something like this : haproxy -sf $(pidof haproxy) -- /etc/haproxy/global.cfg /etc/haproxy/customers/*.cfg --- src/haproxy.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/haproxy.c b/src/haproxy.c index 90bbb95a0..217247d6d 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -416,7 +416,7 @@ void usage(char *name) fprintf(stderr, "Usage : %s [-f ]* [ -vdV" "D ] [ -n ] [ -N ]\n" - " [ -p ] [ -m ] [ -C ]\n" + " [ -p ] [ -m ] [ -C ] [-- *]\n" " -v displays version ; -vv shows known build options.\n" " -d enters debug mode ; -db only disables background mode.\n" " -dM[] poisons memory with (defaults to 0x50)\n" @@ -702,6 +702,21 @@ void init(int argc, char **argv) nb_oldpids++; } } + else if (flag[0] == '-' && flag[1] == 0) { /* "--" */ + /* now that's a cfgfile list */ + argv++; argc--; + while (argc > 0) { + wl = (struct wordlist *)calloc(1, sizeof(*wl)); + if (!wl) { + Alert("Cannot load configuration file %s : out of memory.\n", *argv); + exit(1); + } + wl->s = *argv; + LIST_ADDQ(&cfg_cfgfiles, &wl->list); + argv++; argc--; + } + break; + } else { /* >=2 args */ argv++; argc--; if (argc == 0)