From: Erwan Le Goas Date: Thu, 29 Sep 2022 08:34:04 +0000 (+0200) Subject: MINOR: config: Add option line when the configuration file is dumped X-Git-Tag: v2.7-dev7~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f30c5d76665d8413c875b81b10c384ae9240d5f2;p=thirdparty%2Fhaproxy.git MINOR: config: Add option line when the configuration file is dumped Add an option to dump the number lines of the configuration file when it's dumped. Other options can be easily added. Options are separated by ',' when tapping the command line: './haproxy -dC[key],line -f [file]' No backport needed, except if anonymization mechanism is backported. --- diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h index f10146e490..7840eabff4 100644 --- a/include/haproxy/global-t.h +++ b/include/haproxy/global-t.h @@ -43,6 +43,7 @@ #define MODE_DUMP_LIBS 0x2000 /* dump loaded libraries at the end of init phase */ #define MODE_DUMP_KWD 0x4000 /* dump registered keywords (see kwd_dump for the list) */ #define MODE_DUMP_CFG 0x8000 /* dump the configure file */ +#define MODE_DUMP_NB_L 0x10000 /* dump line numbers when the configuration file is dump */ /* list of last checks to perform, depending on config options */ #define LSTCHK_CAP_BIND 0x00000001 /* check that we can bind to any port */ diff --git a/src/cfgparse.c b/src/cfgparse.c index d0cca04983..0c865c893e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1901,7 +1901,8 @@ next_line: int i = 0; uint32_t g_key = HA_ATOMIC_LOAD(&global.anon_key); - qfprintf(stdout, "%d\t", linenum); + if (global.mode & MODE_DUMP_NB_L) + qfprintf(stdout, "%d\t", linenum); /* if a word is in sections list, is_sect = 1 */ list_for_each_entry(sect, §ions, list) { diff --git a/src/haproxy.c b/src/haproxy.c index 1ec16b7d79..ab37f3e141 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -590,7 +590,7 @@ static void usage(char *name) " -N sets the default, per-proxy maximum # of connections (%d)\n" " -L set local peer name (default to hostname)\n" " -p writes pids of all children to this file\n" - " -dC[key] display the configure file, if there is a key, the file will be anonymise\n" + " -dC[[key],line] display the configuration file, if there is a key, the file will be anonymised\n" #if defined(USE_EPOLL) " -de disables epoll() usage even when available\n" #endif @@ -1636,6 +1636,19 @@ static void init_args(int argc, char **argv) else if (*flag == 'V') arg_mode |= MODE_VERBOSE; else if (*flag == 'd' && flag[1] == 'C') { + char *end; + char *key; + + key = flag + 2; + for (;key && *key; key = end) { + end = strchr(key, ','); + if (end) + *(end++) = 0; + + if (strcmp(key, "line") == 0) + arg_mode |= MODE_DUMP_NB_L; + + } arg_mode |= MODE_DUMP_CFG; HA_ATOMIC_STORE(&global.anon_key, atoll(flag + 2)); } @@ -1910,7 +1923,8 @@ static void init(int argc, char **argv) global.mode |= (arg_mode & (MODE_DAEMON | MODE_MWORKER | MODE_FOREGROUND | MODE_VERBOSE | MODE_QUIET | MODE_CHECK | MODE_DEBUG | MODE_ZERO_WARNING - | MODE_DIAG | MODE_CHECK_CONDITION | MODE_DUMP_LIBS | MODE_DUMP_KWD | MODE_DUMP_CFG)); + | MODE_DIAG | MODE_CHECK_CONDITION | MODE_DUMP_LIBS | MODE_DUMP_KWD + | MODE_DUMP_CFG | MODE_DUMP_NB_L)); if (getenv("HAPROXY_MWORKER_WAIT_ONLY")) { unsetenv("HAPROXY_MWORKER_WAIT_ONLY");