]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: Add option line when the configuration file is dumped
authorErwan Le Goas <elegoas@haproxy.com>
Thu, 29 Sep 2022 08:34:04 +0000 (10:34 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 29 Sep 2022 08:53:15 +0000 (10:53 +0200)
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.

include/haproxy/global-t.h
src/cfgparse.c
src/haproxy.c

index f10146e4900cbef00d54c5a1d661c9cbc3c4505a..7840eabff477aa3cd32c159cf9784dc6c25ea24f 100644 (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 */
index d0cca04983573b3e2663f1f5bb0ff0355dfeb852..0c865c893e0ee3dd859faf2ad399255e799fc732 100644 (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) {
index 1ec16b7d79fb05100f90ff977e14ba9a11697b3c..ab37f3e141fa667d3703f365095681eebba9f4c7 100644 (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");