From: Valentine Krasnobaeva Date: Mon, 7 Oct 2024 09:44:48 +0000 (+0200) Subject: MINOR: startup: add read_cfg_in_discovery_mode X-Git-Tag: v3.1-dev10~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6615e464562ceeea0fd480a32d73e3b5af73eef7;p=thirdparty%2Fhaproxy.git MINOR: startup: add read_cfg_in_discovery_mode Let's encapsulate here the code to load and to read the configuration at the first time in MODE_DISCOVERY. This makes the code of main() more readable and this adds the structure for adding necessary master initializations routines to support master recovery mode. --- diff --git a/src/haproxy.c b/src/haproxy.c index 89ba8e3a71..39dc3be9d8 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -3006,6 +3006,38 @@ static void step_init_4(void) ha_free(&global.pidfile); } +/* parse conf in disovery mode and set modes from config */ +static void read_cfg_in_discovery_mode(int argc, char **argv) +{ + struct cfgfile *cfg, *cfg_tmp; + int ret; + + /* load configs and read only the keywords with KW_DISCOVERY flag */ + global.mode |= MODE_DISCOVERY; + + usermsgs_clr("config"); + ret = load_cfg(progname); + if (ret == 0) { + /* read only global section in discovery mode */ + ret = read_cfg(progname); + } + if (ret < 0) { + list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) { + ha_free(&cfg->content); + ha_free(&cfg->filename); + } + exit(1); + } + usermsgs_clr(NULL); + + global.mode &= ~MODE_DISCOVERY; + + if (!LIST_ISEMPTY(&mworker_cli_conf) && !(arg_mode & MODE_MWORKER)) { + ha_alert("a master CLI socket was defined, but master-worker mode (-W) is not enabled.\n"); + exit(EXIT_FAILURE); + } +} + void deinit(void) { struct proxy *p = proxies_list, *p0; @@ -3537,7 +3569,6 @@ static void set_identity(const char *program_name) int main(int argc, char **argv) { - int ret; int devnullfd = -1; struct rlimit limit; int intovf = (unsigned char)argc + 1; /* let the compiler know it's strictly positive */ @@ -3624,30 +3655,8 @@ int main(int argc, char **argv) */ step_init_1(); - /* load configs and read only the keywords with KW_DISCOVERY flag */ - global.mode |= MODE_DISCOVERY; - - usermsgs_clr("config"); - ret = load_cfg(progname); - if (ret == 0) { - /* read only global section in discovery mode */ - ret = read_cfg(progname); - } - if (ret < 0) { - list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) { - ha_free(&cfg->content); - ha_free(&cfg->filename); - } - exit(1); - } - usermsgs_clr(NULL); - - global.mode &= ~MODE_DISCOVERY; - - if (!LIST_ISEMPTY(&mworker_cli_conf) && !(arg_mode & MODE_MWORKER)) { - ha_alert("a master CLI socket was defined, but master-worker mode (-W) is not enabled.\n"); - exit(EXIT_FAILURE); - } + /* parse conf in disovery mode and set modes from config */ + read_cfg_in_discovery_mode(argc, 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.