]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: startup: add set_verbosity
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 8 Oct 2024 14:08:28 +0000 (16:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
Let's encapsulate the logic to set verbosity modes (MODE_DEBUG and MODE_VERBOSE)
in a separate function set_verbosity(). This makes the code of main() more
readable and this allows to call set_verbosity() for master process in recovery
mode. So, in this mode, verbosity settings before the master re-execution will
be re-applied to master. set_verbosity() will be extended in future commits to
reduce the verbosiness of master in order not to dump pollers list and filters,
if it was started with -V or -d.

src/haproxy.c

index 52b7fc06e42c668330d4b0ddde18c228792a84f9..5ed6c7edb3054150017bac765d5ff488619fa677 100644 (file)
@@ -2715,25 +2715,6 @@ static void step_init_2(int argc, char** argv)
        if (global.tune.maxrewrite >= global.tune.bufsize / 2)
                global.tune.maxrewrite = global.tune.bufsize / 2;
 
-       if (arg_mode & (MODE_DEBUG | MODE_FOREGROUND)) {
-               /* command line debug mode inhibits configuration mode */
-               global.mode &= ~(MODE_DAEMON | MODE_QUIET);
-               global.mode |= (arg_mode & (MODE_DEBUG | MODE_FOREGROUND));
-       }
-
-       if (arg_mode & MODE_DAEMON) {
-               /* command line daemon mode inhibits foreground and debug modes mode */
-               global.mode &= ~(MODE_DEBUG | MODE_FOREGROUND);
-               global.mode |= arg_mode & MODE_DAEMON;
-       }
-
-       global.mode |= (arg_mode & (MODE_QUIET | MODE_VERBOSE));
-
-       if ((global.mode & MODE_DEBUG) && (global.mode & (MODE_DAEMON | MODE_QUIET))) {
-               ha_warning("<debug> mode incompatible with <quiet> and <daemon>. Keeping <debug> only.\n");
-               global.mode &= ~(MODE_DAEMON | MODE_QUIET);
-       }
-
        /* Realloc trash buffers because global.tune.bufsize may have changed */
        if (!init_trash_buffers(0)) {
                ha_alert("failed to initialize trash buffers.\n");
@@ -3001,6 +2982,32 @@ static void step_init_4(void)
        ha_free(&global.pidfile);
 }
 
+/* This function sets verbosity modes. Should be called after the first
+ * configuration read in order that in master-worker mode, both master and
+ * worker have the same verbosiness.
+ */
+static void set_verbosity(void) {
+
+       if (arg_mode & (MODE_DEBUG | MODE_FOREGROUND)) {
+               /* command line debug mode inhibits configuration mode */
+               global.mode &= ~(MODE_DAEMON | MODE_QUIET);
+               global.mode |= (arg_mode & (MODE_DEBUG | MODE_FOREGROUND));
+       }
+
+       if (arg_mode & MODE_DAEMON) {
+               /* command line daemon mode inhibits foreground and debug modes mode */
+               global.mode &= ~(MODE_DEBUG | MODE_FOREGROUND);
+               global.mode |= arg_mode & MODE_DAEMON;
+       }
+
+       global.mode |= (arg_mode & (MODE_QUIET | MODE_VERBOSE));
+
+       if ((global.mode & MODE_DEBUG) && (global.mode & (MODE_DAEMON | MODE_QUIET))) {
+               ha_warning("<debug> mode incompatible with <quiet> and <daemon>. Keeping <debug> only.\n");
+               global.mode &= ~(MODE_DAEMON | MODE_QUIET);
+       }
+}
+
 static void run_master_in_recovery_mode(int argc, char **argv)
 {
        struct mworker_proc *proc;
@@ -3014,6 +3021,7 @@ static void run_master_in_recovery_mode(int argc, char **argv)
        global.nbthread = 1;
        master = 1;
        atexit(exit_on_failure);
+       set_verbosity();
 
        /* creates MASTER proxy and attaches server to child->ipc_fd[0] */
        if (mworker_cli_proxy_create() < 0) {
@@ -3712,6 +3720,7 @@ int main(int argc, char **argv)
        /* From this stage all runtime modes are known. So let's do below some
         * preparation steps and then let's apply all discovered modes.
         */
+       set_verbosity();
 
        /* Add entries for master and worker in proc_list, create sockpair,
         * that will be copied to both processes after master-worker fork to