Skip to content

Commit 1f0cd91

Browse files
einval22wlallemand
authored andcommitted
BUG/MINOR: startup: set HAPROXY_CFGFILES in read_cfg
load_cfg() is called only once before the first reading of the configuration (we parse here only the global section). Then, before reading the rest of the sections (second call of read_cfg()), we call clean_env(). As HAPROXY_CFGFILES is set in load_cfg(), which is called only once, clean_env() erases it. Thus, it's not longer shown in "show env" output. To fix this, let's set HAPROXY_CFGFILES in read_cfg(). Like this in master-worker mode it is set for master and for worker processes, as it was before the refactoring. This fix doesn't need to be backported as related to the latest master-worker architecture change.
1 parent d5d41de commit 1f0cd91

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/haproxy.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,6 @@ static void cfgfiles_expand_directories(void)
11801180
static int load_cfg(char *progname)
11811181
{
11821182
struct cfgfile *cfg, *cfg_tmp;
1183-
char *env_cfgfiles = NULL;
11841183

11851184
/* handle cfgfiles that are actually directories */
11861185
cfgfiles_expand_directories();
@@ -1192,24 +1191,11 @@ static int load_cfg(char *progname)
11921191

11931192
cfg->size = load_cfg_in_mem(cfg->filename, &cfg->content);
11941193
if (cfg->size < 0)
1195-
goto err;
1194+
return -1;
11961195

1197-
if (!memprintf(&env_cfgfiles, "%s%s%s",
1198-
(env_cfgfiles ? env_cfgfiles : ""),
1199-
(env_cfgfiles ? ";" : ""), cfg->filename)) {
1200-
/* free what we've already allocated and free cfglist */
1201-
ha_alert("Could not allocate memory for HAPROXY_CFGFILES env variable\n");
1202-
goto err;
1203-
}
12041196
}
12051197

1206-
setenv("HAPROXY_CFGFILES", env_cfgfiles, 1);
1207-
free(env_cfgfiles);
1208-
12091198
return 0;
1210-
err:
1211-
free(env_cfgfiles);
1212-
return -1;
12131199

12141200
}
12151201

@@ -1221,6 +1207,7 @@ static int load_cfg(char *progname)
12211207
*/
12221208
static int read_cfg(char *progname)
12231209
{
1210+
char *env_cfgfiles = NULL;
12241211
struct cfgfile *cfg;
12251212
int err_code = 0;
12261213

@@ -1237,15 +1224,28 @@ static int read_cfg(char *progname)
12371224
list_for_each_entry(cfg, &cfg_cfgfiles, list) {
12381225
int ret;
12391226

1227+
/* save all successfully loaded conf files in HAPROXY_CFGFILES
1228+
* env var
1229+
*/
1230+
if (!memprintf(&env_cfgfiles, "%s%s%s",
1231+
(env_cfgfiles ? env_cfgfiles : ""),
1232+
(env_cfgfiles ? ";" : ""), cfg->filename)) {
1233+
/* free what we've already allocated and free cfglist */
1234+
ha_alert("Could not allocate memory for HAPROXY_CFGFILES env variable\n");
1235+
goto err;
1236+
}
1237+
12401238
ret = parse_cfg(cfg);
12411239
if (ret == -1)
1242-
return -1;
1240+
goto err;
12431241

12441242
if (ret & (ERR_ABORT|ERR_FATAL))
12451243
ha_alert("Error(s) found in configuration file : %s\n", cfg->filename);
12461244
err_code |= ret;
12471245
if (err_code & ERR_ABORT)
1248-
return -1;
1246+
goto err;
1247+
1248+
12491249
}
12501250
/* remove temporary environment variables. */
12511251
unsetenv("HAPROXY_BRANCH");
@@ -1260,10 +1260,17 @@ static int read_cfg(char *progname)
12601260
*/
12611261
if (err_code & (ERR_ABORT|ERR_FATAL)) {
12621262
ha_alert("Fatal errors found in configuration.\n");
1263-
return -1;
1263+
goto err;
12641264
}
12651265

1266+
setenv("HAPROXY_CFGFILES", env_cfgfiles, 1);
1267+
free(env_cfgfiles);
1268+
12661269
return err_code;
1270+
1271+
err:
1272+
free(env_cfgfiles);
1273+
return -1;
12671274
}
12681275

12691276
/*

0 commit comments

Comments
 (0)