From cac8ef431e654b001f2416bbddf4612b81248aca Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 20 Nov 2014 15:52:55 +0100 Subject: MAJOR: httpterm: create a listener on the fly on -L -L on the command line replaces localpeer and creates a dummy HTTP listener instead, just as with httpterm 1.1. --- src/haproxy.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index a306952..16098d5 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -196,6 +196,7 @@ const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 }; char hostname[MAX_HOSTNAME_LEN]; char localpeer[MAX_HOSTNAME_LEN]; +static char *cmd_listener; /* used from everywhere just to drain results we don't want to read and which * recent versions of gcc increasingly and annoyingly complain about. @@ -385,7 +386,7 @@ void usage(char *name) " -n sets the maximum total # of connections (%d)\n" " -m limits the usable amount of memory (in MB)\n" " -N sets the default, per-proxy maximum # of connections (%d)\n" - " -L set local peer name (default to hostname)\n" + " -L []:[,...] adds a listener with one server\n" " -p writes pids of all children to this file\n" #if defined(ENABLE_EPOLL) " -de disables epoll() usage even when available\n" @@ -665,7 +666,7 @@ void init(int argc, char **argv) case 'n' : cfg_maxconn = atol(*argv); break; case 'm' : global.rlimit_memmax = atol(*argv); break; case 'N' : cfg_maxpconn = atol(*argv); break; - case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break; + case 'L' : cmd_listener = *argv; break; case 'f' : wl = (struct wordlist *)calloc(1, sizeof(*wl)); if (!wl) { @@ -689,7 +690,7 @@ void init(int argc, char **argv) (arg_mode & (MODE_DAEMON | MODE_SYSTEMD | MODE_FOREGROUND | MODE_VERBOSE | MODE_QUIET | MODE_CHECK | MODE_DEBUG)); - if (LIST_ISEMPTY(&cfg_cfgfiles)) + if (LIST_ISEMPTY(&cfg_cfgfiles) && !cmd_listener) usage(progname); if (change_dir && chdir(change_dir) < 0) { @@ -702,6 +703,39 @@ void init(int argc, char **argv) init_default_instance(); + if (cmd_listener) { + char *args[10]; + + args[0] = "frontend"; + args[1] = "cmdline"; + args[2] = "\0"; + + if (cfg_parse_listen("command_line", 1, args, 0) != 0) + exit(1); + + args[0] = "bind"; + args[1] = cmd_listener; + args[2] = "\0"; + + if (cfg_parse_listen("command_line", 2, args, 0) != 0) + exit(1); + + args[0] = "mode"; + args[1] = "http"; + args[2] = "\0"; + + if (cfg_parse_listen("command_line", 3, args, 0) != 0) + exit(1); + + args[0] = "timeout"; + args[1] = "client"; + args[2] = "10s"; + args[3] = "\0"; + + if (cfg_parse_listen("command_line", 4, args, 0) != 0) + exit(1); + } + list_for_each_entry(wl, &cfg_cfgfiles, list) { int ret; -- 1.7.12.1