From: Willy Tarreau Date: Sat, 10 Sep 2011 17:26:56 +0000 (+0200) Subject: [MINOR] startup: add an option to change to a new directory X-Git-Tag: v1.5-dev8~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=576132e5336aa7011df021fc9409a07d73d646d3;p=thirdparty%2Fhaproxy.git [MINOR] startup: add an option to change to a new directory Passing -C causes haproxy to chdir to before loading any file. The argument may be passed anywhere on the command line. A typical use case is : $ haproxy -C /etc/haproxy -f global.cfg -f haproxy.cfg --- diff --git a/src/haproxy.c b/src/haproxy.c index 0204d06b52..f54fc8eae6 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -220,11 +220,11 @@ void usage(char *name) fprintf(stderr, "Usage : %s [-f ]* [ -vdV" "D ] [ -n ] [ -N ]\n" - " [ -p ] [ -m ]\n" + " [ -p ] [ -m ] [ -C ]\n" " -v displays version ; -vv shows known build options.\n" " -d enters debug mode ; -db only disables background mode.\n" " -V enters verbose mode (disables quiet mode)\n" - " -D goes daemon\n" + " -D goes daemon ; -C changes to before loading files.\n" " -q quiet mode : don't display messages\n" " -c check mode : only check config files and exit\n" " -n sets the maximum total # of connections (%d)\n" @@ -357,6 +357,7 @@ void init(int argc, char **argv) int err_code = 0; struct wordlist *wl; char *progname; + char *change_dir = NULL; /* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate * the string in case of truncation, and at least FreeBSD appears not to do @@ -485,6 +486,7 @@ void init(int argc, char **argv) usage(progname); switch (*flag) { + case 'C' : change_dir = *argv; break; case 'n' : cfg_maxconn = atol(*argv); break; case 'm' : global.rlimit_memmax = atol(*argv); break; case 'N' : cfg_maxpconn = atol(*argv); break; @@ -515,6 +517,11 @@ void init(int argc, char **argv) if (LIST_ISEMPTY(&cfg_cfgfiles)) usage(progname); + if (change_dir && chdir(change_dir) < 0) { + Alert("Could not change to directory %s : %s\n", change_dir, strerror(errno)); + exit(1); + } + have_appsession = 0; global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket eaters */