From: Willy Tarreau Date: Mon, 26 Nov 2018 10:33:13 +0000 (+0100) Subject: MINOR: initcall: use initcalls for section parsers X-Git-Tag: v1.9-dev9~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e655251e80a927b2792ebae2ea50903c55c675a4;p=thirdparty%2Fhaproxy.git MINOR: initcall: use initcalls for section parsers The two calls to cfg_register_section() and cfg_register_postparser() are now supported by initcalls. This allowed to remove two other constructors. --- diff --git a/include/common/cfgparse.h b/include/common/cfgparse.h index 3069722838..b46e02b99c 100644 --- a/include/common/cfgparse.h +++ b/include/common/cfgparse.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -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 */ /* diff --git a/src/cache.c b/src/cache.c index acab99da0f..7f1de9f326 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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); diff --git a/src/cfgparse.c b/src/cfgparse.c index 1e6566856f..5df53d3480 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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: diff --git a/src/dns.c b/src/dns.c index 255f15a96c..2aac74ffe3 100644 --- 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); diff --git a/src/hlua.c b/src/hlua.c index 294b6b3f53..379eef691c 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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);