]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEIDUM: startup: return to initial cwd only after check_config_validity()
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 4 Mar 2025 10:04:01 +0000 (11:04 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 6 Mar 2025 09:49:48 +0000 (10:49 +0100)
In check_config_validity() we evaluate some sample fetch expressions
(log-format, server rules, etc). These expressions may use external files like
maps.

If some particular 'default-path' was set in the global section before, it's no
longer applied to resolve file pathes in check_config_validity(). parse_cfg()
at the end of config parsing switches back to the initial cwd.

This fixes the issue #2886.

This patch should be backported in all stable versions since 2.4.0, including
2.4.0.

include/haproxy/cfgparse.h
src/cfgparse.c
src/haproxy.c

index 5b8bc07596b94be58d94d8513ccedd515f54ecc6..760d54e01bdba44adc97e69255303594c30b9606 100644 (file)
@@ -110,6 +110,7 @@ extern char *cursection;
 extern int non_global_section_parsed;
 
 extern struct proxy *curproxy;
+extern char initial_cwd[PATH_MAX];
 
 int cfg_parse_global(const char *file, int linenum, char **args, int inv);
 int cfg_parse_listen(const char *file, int linenum, char **args, int inv);
index 75d044fb8a39334cf1a927853fc137b533e81da0..c99a7339edae4f2f86c7ebb1432758cdcf513f3f 100644 (file)
@@ -121,7 +121,7 @@ static enum default_path_mode {
        DEFAULT_PATH_ORIGIN,       /* "origin": paths are relative to default_path_origin */
 } default_path_mode;
 
-static char initial_cwd[PATH_MAX];
+char initial_cwd[PATH_MAX];
 static char current_cwd[PATH_MAX];
 
 /* List head of all known configuration keywords */
@@ -2668,11 +2668,6 @@ section_parser:
                err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT;
        }
 
-       if (*initial_cwd && chdir(initial_cwd) == -1) {
-               ha_alert("Impossible to get back to initial directory '%s' : %s\n", initial_cwd, strerror(errno));
-               err_code |= ERR_ALERT | ERR_FATAL;
-       }
-
 err:
        ha_free(&cfg_scope);
        cursection = NULL;
index 90b89f9b851e4120a44033d251ebf11a2ab2d78d..8804d0529b9a1174e00be62a95305b4039e33501 100644 (file)
@@ -2052,6 +2052,10 @@ static void step_init_2(int argc, char** argv)
 
        /* Note: global.nbthread will be initialized as part of this call */
        err_code |= check_config_validity();
+       if (*initial_cwd && chdir(initial_cwd) == -1) {
+               ha_alert("Impossible to get back to initial directory '%s' : %s\n", initial_cwd, strerror(errno));
+               exit(1);
+       }
 
        /* update the ready date to also account for the check time */
        clock_update_date(0, 1);