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
diff --git a/src/haproxy.c b/src/haproxy.c
index 90bbb95..217247d 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -416,7 +416,7 @@
fprintf(stderr,
"Usage : %s [-f <cfgfile>]* [ -vdV"
"D ] [ -n <maxconn> ] [ -N <maxpconn> ]\n"
- " [ -p <pidfile> ] [ -m <max megs> ] [ -C <dir> ]\n"
+ " [ -p <pidfile> ] [ -m <max megs> ] [ -C <dir> ] [-- <cfgfile>*]\n"
" -v displays version ; -vv shows known build options.\n"
" -d enters debug mode ; -db only disables background mode.\n"
" -dM[<byte>] poisons memory with <byte> (defaults to 0x50)\n"
@@ -702,6 +702,21 @@
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)