BUG/MEDIUM: config: fix multiple declaration of section parsers
Ben Cabot reported that after commit 5e4261b ("CLEANUP: config:
detect double registration of a config section") recently introduced
in 1.7-dev, it's not possible anymore to load multiple configuration
files. Bryan Talbot provided a simple reproducer to exhibit the issue.
It turns out that function readcfgfile() registers new parsers for
section keywords for each new file. In addition to being useless, this
has the negative effect of wasting memory and slowing down the config
parser as the number of configuration files increases.
This fix only needs to be backported if/where the commit above is
backported.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 9b76465..fed5bd5 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -6968,19 +6968,6 @@
return -1;
}
- /* Register internal sections */
- if (!cfg_register_section("listen", cfg_parse_listen) ||
- !cfg_register_section("frontend", cfg_parse_listen) ||
- !cfg_register_section("backend", cfg_parse_listen) ||
- !cfg_register_section("defaults", cfg_parse_listen) ||
- !cfg_register_section("global", cfg_parse_global) ||
- !cfg_register_section("userlist", cfg_parse_users) ||
- !cfg_register_section("peers", cfg_parse_peers) ||
- !cfg_register_section("mailers", cfg_parse_mailers) ||
- !cfg_register_section("namespace_list", cfg_parse_netns) ||
- !cfg_register_section("resolvers", cfg_parse_resolvers))
- return -1;
-
if ((f=fopen(file,"r")) == NULL) {
free(thisline);
return -1;
@@ -9132,6 +9119,22 @@
}
}
+__attribute__((constructor))
+static void cfgparse_init(void)
+{
+ /* Register internal sections */
+ cfg_register_section("listen", cfg_parse_listen);
+ cfg_register_section("frontend", cfg_parse_listen);
+ cfg_register_section("backend", cfg_parse_listen);
+ cfg_register_section("defaults", cfg_parse_listen);
+ cfg_register_section("global", cfg_parse_global);
+ cfg_register_section("userlist", cfg_parse_users);
+ cfg_register_section("peers", cfg_parse_peers);
+ cfg_register_section("mailers", cfg_parse_mailers);
+ cfg_register_section("namespace_list", cfg_parse_netns);
+ cfg_register_section("resolvers", cfg_parse_resolvers);
+}
+
/*
* Local variables:
* c-indent-level: 8