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.
This commit is contained in:
Erwan Le Goas 2022-09-29 10:34:04 +02:00 committed by Christopher Faulet
parent 059d05f702
commit f30c5d7666
3 changed files with 19 additions and 3 deletions

View File

@ -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 */

View File

@ -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, &sections, list) {

View File

@ -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");