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.
This commit is contained in:
Valentine Krasnobaeva 2024-10-07 11:44:48 +02:00 committed by Willy Tarreau
parent 1cee184145
commit 6615e46456

View File

@ -3006,6 +3006,38 @@ static void step_init_4(void)
ha_free(&global.pidfile); 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) void deinit(void)
{ {
struct proxy *p = proxies_list, *p0; 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 main(int argc, char **argv)
{ {
int ret;
int devnullfd = -1; int devnullfd = -1;
struct rlimit limit; struct rlimit limit;
int intovf = (unsigned char)argc + 1; /* let the compiler know it's strictly positive */ 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(); step_init_1();
/* load configs and read only the keywords with KW_DISCOVERY flag */ /* parse conf in disovery mode and set modes from config */
global.mode |= MODE_DISCOVERY; read_cfg_in_discovery_mode(argc, argv);
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);
}
/* From this stage all runtime modes are known. So let's do below some /* From this stage all runtime modes are known. So let's do below some
* preparation steps and then let's apply all discovered modes. * preparation steps and then let's apply all discovered modes.