]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: init: do MODE_CHECK_CONDITION logic first
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 26 Jun 2024 16:29:47 +0000 (18:29 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 27 Jun 2024 13:59:43 +0000 (15:59 +0200)
In MODE_CHECK_CONDITION we only parse check_condition string, provided by
'-cc', and then we evaluate it. Haproxy process terminates at the
end of {if..else} block anyway, if the test has failed or passed. So, it
will be more appropriate to perform MODE_CHECK_CONDITION test first and
then do all other process runtime mode verifications.

src/haproxy.c

index afccf0912675a654780de72ce855f7719a1c5988..155779e3ec7ec62c242289da30dd204e3b72bb78 100644 (file)
@@ -2063,26 +2063,6 @@ static void init(int argc, char **argv)
                global.mode &= ~MODE_MWORKER;
        }
 
-       /* set the atexit functions when not doing configuration check */
-       if (!(global.mode & (MODE_CHECK | MODE_CHECK_CONDITION))
-           && (getenv("HAPROXY_MWORKER_REEXEC") != NULL)) {
-
-               if (global.mode & MODE_MWORKER) {
-                       atexit_flag = 1;
-                       atexit(reexec_on_failure);
-               } else if (global.mode & MODE_MWORKER_WAIT) {
-                       atexit_flag = 1;
-                       atexit(exit_on_waitmode_failure);
-               }
-       }
-
-       if (change_dir && chdir(change_dir) < 0) {
-               ha_alert("Could not change to directory %s : %s\n", change_dir, strerror(errno));
-               exit(1);
-       }
-
-       usermsgs_clr("config");
-
        if (global.mode & MODE_CHECK_CONDITION) {
                int result;
 
@@ -2144,6 +2124,25 @@ static void init(int argc, char **argv)
                exit(result ? 0 : 1);
        }
 
+       /* set the atexit functions when not doing configuration check */
+       if (!(global.mode & MODE_CHECK) && (getenv("HAPROXY_MWORKER_REEXEC") != NULL)) {
+
+               if (global.mode & MODE_MWORKER) {
+                       atexit_flag = 1;
+                       atexit(reexec_on_failure);
+               } else if (global.mode & MODE_MWORKER_WAIT) {
+                       atexit_flag = 1;
+                       atexit(exit_on_waitmode_failure);
+               }
+       }
+
+       if (change_dir && chdir(change_dir) < 0) {
+               ha_alert("Could not change to directory %s : %s\n", change_dir, strerror(errno));
+               exit(1);
+       }
+
+       usermsgs_clr("config");
+
        /* in wait mode, we don't try to read the configuration files */
        if (!(global.mode & MODE_MWORKER_WAIT)) {
                char *env_cfgfiles = NULL;