From: Valentine Krasnobaeva Date: Tue, 8 Oct 2024 14:08:28 +0000 (+0200) Subject: MINOR: startup: add set_verbosity X-Git-Tag: v3.1-dev10~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5be14b338a837ee32ff951dbbd50fcabf7c7cae2;p=thirdparty%2Fhaproxy.git MINOR: startup: add set_verbosity 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. --- diff --git a/src/haproxy.c b/src/haproxy.c index 52b7fc06e4..5ed6c7edb3 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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(" mode incompatible with and . Keeping 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(" mode incompatible with and . Keeping 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