]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: init: support a list of files on the command line
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2015 09:58:48 +0000 (11:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2015 09:58:48 +0000 (11:58 +0200)
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

index 90bbb95a07a8615e0268d2e91602bd2ea2331fe4..217247d6d71ec25f262f306585b49b0c9868f027 100644 (file)
@@ -416,7 +416,7 @@ void usage(char *name)
        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 @@ 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)