]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: startup: add read_cfg_in_discovery_mode
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 7 Oct 2024 09:44:48 +0000 (11:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
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.

src/haproxy.c

index 89ba8e3a710919ab0bd389b69bcb4e66d56b8b1a..39dc3be9d8b4e55d1f4fa8635564710654255389 100644 (file)
@@ -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.