return ret;
}
-/* append a copy of string <str> (in a wordlist) at the end of the list <li>
+/* append a copy of string <filename>, ptr to some allocated memory at the at
+ * the end of the list <li>.
* On failure : return 0 and <err> filled with an error message.
- * The caller is responsible for freeing the <err> and <str> copy
- * memory area using free()
+ * The caller is responsible for freeing the <err> and <filename> copy
+ * memory area using free().
*/
-int list_append_word(struct list *li, const char *str, char **err)
+int list_append_cfgfile(struct list *li, const char *filename, char **err)
{
- struct wordlist *wl;
+ struct cfgfile *entry = NULL;
- wl = calloc(1, sizeof(*wl));
- if (!wl) {
+ entry = calloc(1, sizeof(*entry));
+ if (!entry) {
memprintf(err, "out of memory");
- goto fail_wl;
+ goto fail_entry;
}
- wl->s = strdup(str);
- if (!wl->s) {
+ entry->filename = strdup(filename);
+ if (!entry->filename) {
memprintf(err, "out of memory");
- goto fail_wl_s;
+ goto fail_entry_name;
}
- LIST_APPEND(li, &wl->list);
+ LIST_APPEND(li, &entry->list);
return 1;
-fail_wl_s:
- free(wl->s);
-fail_wl:
- free(wl);
+fail_entry_name:
+ free(entry->filename);
+fail_entry:
+ free(entry);
return 0;
}
*/
static void cfgfiles_expand_directories(void)
{
- struct wordlist *wl, *wlb;
+ struct cfgfile *cfg, *cfg_tmp;
char *err = NULL;
- list_for_each_entry_safe(wl, wlb, &cfg_cfgfiles, list) {
+ list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) {
struct stat file_stat;
struct dirent **dir_entries = NULL;
int dir_entries_nb;
int dir_entries_it;
- if (stat(wl->s, &file_stat)) {
+ if (stat(cfg->filename, &file_stat)) {
ha_alert("Cannot open configuration file/directory %s : %s\n",
- wl->s,
+ cfg->filename,
strerror(errno));
exit(1);
}
if (!S_ISDIR(file_stat.st_mode))
continue;
- /* from this point wl->s is a directory */
+ /* from this point cfg->name is a directory */
- dir_entries_nb = scandir(wl->s, &dir_entries, NULL, alphasort);
+ dir_entries_nb = scandir(cfg->filename, &dir_entries, NULL, alphasort);
if (dir_entries_nb < 0) {
ha_alert("Cannot open configuration directory %s : %s\n",
- wl->s,
+ cfg->filename,
strerror(errno));
exit(1);
}
- /* for each element in the directory wl->s */
+ /* for each element in the directory cfg->name */
for (dir_entries_it = 0; dir_entries_it < dir_entries_nb; dir_entries_it++) {
struct dirent *dir_entry = dir_entries[dir_entries_it];
char *filename = NULL;
!(d_name_cfgext && d_name_cfgext[4] == '\0'))
goto next_dir_entry;
- if (!memprintf(&filename, "%s/%s", wl->s, dir_entry->d_name)) {
+ if (!memprintf(&filename, "%s/%s", cfg->filename, dir_entry->d_name)) {
ha_alert("Cannot load configuration files %s : out of memory.\n",
filename);
exit(1);
if (stat(filename, &file_stat)) {
ha_alert("Cannot open configuration file %s : %s\n",
- wl->s,
+ cfg->filename,
strerror(errno));
exit(1);
}
if (!S_ISREG(file_stat.st_mode))
goto next_dir_entry;
- if (!list_append_word(&wl->list, filename, &err)) {
+ if (!list_append_cfgfile(&cfg->list, filename, &err)) {
ha_alert("Cannot load configuration files %s : %s\n",
filename,
err);
free(dir_entries);
- /* remove the current directory (wl) from cfg_cfgfiles */
- free(wl->s);
- LIST_DELETE(&wl->list);
- free(wl);
+ /* remove the current directory (cfg) from cfgfiles */
+ free(cfg->filename);
+ LIST_DELETE(&cfg->list);
+ free(cfg);
}
free(err);
{
char *env_cfgfiles = NULL;
int env_err = 0;
- struct wordlist *wl;
+ struct cfgfile *cfg;
int err_code = 0;
/* handle cfgfiles that are actually directories */
setenv("HAPROXY_HTTPS_LOG_FMT", default_https_log_format, 1);
setenv("HAPROXY_TCP_LOG_FMT", default_tcp_log_format, 1);
setenv("HAPROXY_BRANCH", PRODUCT_BRANCH, 1);
- list_for_each_entry(wl, &cfg_cfgfiles, list) {
+ list_for_each_entry(cfg, &cfg_cfgfiles, list) {
int ret;
if (env_err == 0) {
if (!memprintf(&env_cfgfiles, "%s%s%s",
(env_cfgfiles ? env_cfgfiles : ""),
- (env_cfgfiles ? ";" : ""), wl->s))
+ (env_cfgfiles ? ";" : ""), cfg->filename))
env_err = 1;
}
- ret = readcfgfile(wl->s);
+ ret = readcfgfile(cfg->filename);
if (ret == -1) {
ha_alert("Could not open configuration file %s : %s\n",
- wl->s, strerror(errno));
+ cfg->filename, strerror(errno));
free(env_cfgfiles);
exit(1);
}
if (ret & (ERR_ABORT|ERR_FATAL))
- ha_alert("Error(s) found in configuration file : %s\n", wl->s);
+ ha_alert("Error(s) found in configuration file : %s\n", cfg->filename);
err_code |= ret;
if (err_code & ERR_ABORT) {
free(env_cfgfiles);
/* now that's a cfgfile list */
argv++; argc--;
while (argc > 0) {
- if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {
+ if (!list_append_cfgfile(&cfg_cfgfiles, *argv, &err_msg)) {
ha_alert("Cannot load configuration file/directory %s : %s\n",
*argv,
err_msg);
global.localpeer_cmdline = 1;
break;
case 'f' :
- if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {
+ if (!list_append_cfgfile(&cfg_cfgfiles, *argv, &err_msg)) {
ha_alert("Cannot load configuration file/directory %s : %s\n",
*argv,
err_msg);
void deinit(void)
{
struct proxy *p = proxies_list, *p0;
- struct wordlist *wl, *wlb;
+ struct cfgfile *cfg, *cfg_tmp;
struct uri_auth *uap, *ua = NULL;
struct logger *log, *logb;
struct build_opts_str *bol, *bolb;
free_logger(log);
}
- list_for_each_entry_safe(wl, wlb, &cfg_cfgfiles, list) {
- free(wl->s);
- LIST_DELETE(&wl->list);
- free(wl);
+ list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) {
+ ha_free(&cfg->content);
+ ha_free(&cfg->filename);
+ LIST_DELETE(&cfg->list);
+ ha_free(&cfg);
}
list_for_each_entry_safe(bol, bolb, &build_opts_list, list) {