]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: initcall: use initcalls for section parsers
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 10:33:13 +0000 (11:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
The two calls to cfg_register_section() and cfg_register_postparser()
are now supported by initcalls. This allowed to remove two other
constructors.

include/common/cfgparse.h
src/cache.c
src/cfgparse.c
src/dns.c
src/hlua.c

index 30697228384c925b0065b428f951c411de774763..b46e02b99c30ae650a78ec4e9fd8eac85ec4c368 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <common/compat.h>
 #include <common/config.h>
+#include <common/initcall.h>
 #include <common/mini-clist.h>
 
 #include <proto/log.h>
@@ -143,6 +144,13 @@ static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, i
        return 0;
 }
 
+/* simplified way to define a section parser */
+#define REGISTER_CONFIG_SECTION(name, parse, post)                            \
+       INITCALL3(STG_REGISTER, cfg_register_section, (name), (parse), (post))
+
+#define REGISTER_CONFIG_POSTPARSER(name, parser)                              \
+       INITCALL2(STG_REGISTER, cfg_register_postparser, (name), (parser))
+
 #endif /* _COMMON_CFGPARSE_H */
 
 /*
index acab99da0f9487055695972622a3f5794c5d44d5..7f1de9f3261a837994f84ca9a2d4bda986827cb9 100644 (file)
@@ -1215,7 +1215,9 @@ struct applet http_cache_applet = {
 __attribute__((constructor))
 static void __cache_init(void)
 {
-       cfg_register_section("cache", cfg_parse_cache, cfg_post_parse_section_cache);
-       cfg_register_postparser("cache", cfg_cache_postparser);
        pool_head_cache_st = create_pool("cache_st", sizeof(struct cache_st), MEM_F_SHARED);
 }
+
+/* config parsers for this section */
+REGISTER_CONFIG_SECTION("cache", cfg_parse_cache, cfg_post_parse_section_cache);
+REGISTER_CONFIG_POSTPARSER("cache", cfg_cache_postparser);
index 1e6566856f2639e63be5c47372d24534874f1084..5df53d34802c9ca22400f4908f8fd61aca343fcc 100644 (file)
@@ -3851,21 +3851,17 @@ void cfg_restore_sections(struct list *backup_sections)
        }
 }
 
-__attribute__((constructor))
-static void cfgparse_init(void)
-{
-       /* Register internal sections */
-       cfg_register_section("listen",         cfg_parse_listen,    NULL);
-       cfg_register_section("frontend",       cfg_parse_listen,    NULL);
-       cfg_register_section("backend",        cfg_parse_listen,    NULL);
-       cfg_register_section("defaults",       cfg_parse_listen,    NULL);
-       cfg_register_section("global",         cfg_parse_global,    NULL);
-       cfg_register_section("userlist",       cfg_parse_users,     NULL);
-       cfg_register_section("peers",          cfg_parse_peers,     NULL);
-       cfg_register_section("mailers",        cfg_parse_mailers,   NULL);
-       cfg_register_section("namespace_list", cfg_parse_netns,     NULL);
-       cfg_register_section("resolvers",      cfg_parse_resolvers, NULL);
-}
+/* these are the config sections handled by default */
+REGISTER_CONFIG_SECTION("listen",         cfg_parse_listen,    NULL);
+REGISTER_CONFIG_SECTION("frontend",       cfg_parse_listen,    NULL);
+REGISTER_CONFIG_SECTION("backend",        cfg_parse_listen,    NULL);
+REGISTER_CONFIG_SECTION("defaults",       cfg_parse_listen,    NULL);
+REGISTER_CONFIG_SECTION("global",         cfg_parse_global,    NULL);
+REGISTER_CONFIG_SECTION("userlist",       cfg_parse_users,     NULL);
+REGISTER_CONFIG_SECTION("peers",          cfg_parse_peers,     NULL);
+REGISTER_CONFIG_SECTION("mailers",        cfg_parse_mailers,   NULL);
+REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns,     NULL);
+REGISTER_CONFIG_SECTION("resolvers",      cfg_parse_resolvers, NULL);
 
 /*
  * Local variables:
index 255f15a96cf5be19e32557c87c8f5ead81032283..2aac74ffe32d1b522e4e40d3446ad31bf7e44fc7 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -2058,8 +2058,7 @@ static void __dns_init(void)
 {
        dns_answer_item_pool = create_pool("dns_answer_item", sizeof(struct dns_answer_item), MEM_F_SHARED);
        dns_resolution_pool  = create_pool("dns_resolution",  sizeof(struct dns_resolution),  MEM_F_SHARED);
-
-       cfg_register_postparser("dns runtime resolver", dns_finalize_config);
 }
 
 REGISTER_POST_DEINIT(dns_deinit);
+REGISTER_CONFIG_POSTPARSER("dns runtime resolver", dns_finalize_config);
index 294b6b3f5335334d8b1e0faea878a67f598e477b..379eef691c0a4ccbee778bbc3ad40b5d1b482f0c 100644 (file)
@@ -8207,12 +8207,6 @@ void hlua_init(void)
        RESET_SAFE_LJMP(gL.T);
 }
 
-__attribute__((constructor))
-static void __hlua_init(void)
-{
-       cfg_register_postparser("hlua", hlua_check_config);
-}
-
 static void hlua_register_build_options(void)
 {
        char *ptr = NULL;
@@ -8222,3 +8216,4 @@ static void hlua_register_build_options(void)
 }
 
 INITCALL0(STG_REGISTER, hlua_register_build_options);
+REGISTER_CONFIG_POSTPARSER("hlua", hlua_check_config);