]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: initcall: apply initcall to all register_build_opts() calls
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 09:19:54 +0000 (10:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
Most register_build_opts() calls use static strings. These ones were
replaced with a trivial REGISTER_BUILD_OPTS() statement adding the string
and its call to the STG_REGISTER section. A dedicated section could be
made for this if needed, but there are very few such calls for this to
be worth it. The calls made with computed strings however, like those
which retrieve OpenSSL's version or zlib's version, were moved to a
dedicated function to guarantee they are called late in the process.
For example, the SSL call probably requires that SSL_library_init()
has been called first.

12 files changed:
include/types/global.h
src/51d.c
src/auth.c
src/compression.c
src/da.c
src/hathreads.c
src/hlua.c
src/namespace.c
src/proto_tcp.c
src/regex.c
src/ssl_sock.c
src/wurfl.c

index 24eeb0ce79be63e25c1a22b31208372d897c636a..85f5d25c02a3bda50d7ad2bda2f467b514c37b72 100644 (file)
@@ -25,8 +25,9 @@
 #include <netinet/in.h>
 
 #include <common/config.h>
-#include <common/standard.h>
+#include <common/initcall.h>
 #include <common/hathreads.h>
+#include <common/standard.h>
 
 #include <types/listener.h>
 #include <types/proxy.h>
@@ -246,6 +247,10 @@ void hap_register_per_thread_deinit(void (*fct)());
 
 void mworker_accept_wrapper(int fd);
 
+/* simplified way to declare static build options in a file */
+#define REGISTER_BUILD_OPTS(str) \
+       INITCALL2(STG_REGISTER, hap_register_build_opts, (str), 0)
+
 #endif /* _TYPES_GLOBAL_H */
 
 /*
index d537964880cb9fadaed54239d599e3a1edc266c8..d709ec0e7c2db4ed050f78567940796cec18e062 100644 (file)
--- a/src/51d.c
+++ b/src/51d.c
@@ -5,6 +5,7 @@
 #include <common/buffer.h>
 #include <common/errors.h>
 #include <common/initcall.h>
+#include <types/global.h>
 #include <proto/arg.h>
 #include <proto/http_fetch.h>
 #include <proto/log.h>
@@ -689,8 +690,8 @@ INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 __attribute__((constructor))
 static void __51d_init(void)
 {
-       /* register sample fetch and conversion keywords */
-       hap_register_build_opts("Built with 51Degrees support.", 0);
        hap_register_post_check(init_51degrees);
        hap_register_post_deinit(deinit_51degrees);
 }
+
+REGISTER_BUILD_OPTS("Built with 51Degrees support.");
index 2f9cc4fb43c96d60a075eb81fb04a907db5c5e80..8d1da3e3bb6500950ce28accacaddb362c1ec099 100644 (file)
@@ -29,6 +29,7 @@
 #include <common/config.h>
 #include <common/errors.h>
 #include <common/hathreads.h>
+#include <common/initcall.h>
 
 #include <proto/acl.h>
 #include <proto/log.h>
@@ -313,8 +314,4 @@ pat_match_auth(struct sample *smp, struct pattern_expr *expr, int fill)
        return NULL;
 }
 
-__attribute__((constructor))
-static void __auth_init(void)
-{
-       hap_register_build_opts("Encrypted password support via crypt(3): yes", 0);
-}
+REGISTER_BUILD_OPTS("Encrypted password support via crypt(3): yes");
index af44f4d6d11353ded8eac36d16bd91d352cec19b..218a28486854639e90ea09f435d9bd4e11adadf5 100644 (file)
@@ -705,9 +705,6 @@ INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
 __attribute__((constructor))
 static void __comp_fetch_init(void)
 {
-       char *ptr = NULL;
-       int i;
-
 #ifdef USE_SLZ
        slz_make_crc_table();
        slz_prepare_dist_table();
@@ -720,6 +717,13 @@ static void __comp_fetch_init(void)
 #if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
        global.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U;
 #endif
+}
+
+static void comp_register_build_opts(void)
+{
+       char *ptr = NULL;
+       int i;
+
 #ifdef USE_ZLIB
        memprintf(&ptr, "Built with zlib version : " ZLIB_VERSION);
        memprintf(&ptr, "%s\nRunning on zlib version : %s", ptr, zlibVersion());
@@ -738,3 +742,5 @@ static void __comp_fetch_init(void)
 
        hap_register_build_opts(ptr, 1);
 }
+
+INITCALL0(STG_REGISTER, comp_register_build_opts);
index c1c07e397a8324800b4931728e5ffa2c7a8ff5a3..ee3d9af5d9ec1c5489612ddfb4484def10574c0d 100644 (file)
--- a/src/da.c
+++ b/src/da.c
@@ -4,6 +4,7 @@
 #include <common/errors.h>
 #include <common/http.h>
 #include <common/initcall.h>
+#include <types/global.h>
 #include <proto/arg.h>
 #include <proto/http_fetch.h>
 #include <proto/log.h>
@@ -398,8 +399,8 @@ INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 __attribute__((constructor))
 static void __da_init(void)
 {
-       /* register sample fetch and format conversion keywords */
-       hap_register_build_opts("Built with DeviceAtlas support.", 0);
        hap_register_post_check(init_deviceatlas);
        hap_register_post_deinit(deinit_deviceatlas);
 }
+
+REGISTER_BUILD_OPTS("Built with DeviceAtlas support.");
index eb3eb59fb2664c3c1f52dd637ea2eb114e104811..d9128a7fd8d8793ecae33e30b46d9b1a7f02df25 100644 (file)
@@ -17,6 +17,7 @@
 #include <common/cfgparse.h>
 #include <common/hathreads.h>
 #include <common/standard.h>
+#include <types/global.h>
 #include <proto/fd.h>
 
 
@@ -110,7 +111,6 @@ static void __hathreads_init(void)
 #if defined(DEBUG_THREAD) || defined(DEBUG_FULL)
        memset(lock_stats, 0, sizeof(lock_stats));
 #endif
-       hap_register_build_opts("Built with multi-threading support.", 0);
 }
 
 #endif // USE_THREAD
@@ -148,3 +148,5 @@ int parse_nbthread(const char *arg, char **err)
 #endif
        return nbthread;
 }
+
+REGISTER_BUILD_OPTS("Built with multi-threading support.");
index 820ddf58afaec026e7aaa06f8585ccb7410d29d6..294b6b3f5335334d8b1e0faea878a67f598e477b 100644 (file)
@@ -8209,9 +8209,16 @@ void hlua_init(void)
 
 __attribute__((constructor))
 static void __hlua_init(void)
+{
+       cfg_register_postparser("hlua", hlua_check_config);
+}
+
+static void hlua_register_build_options(void)
 {
        char *ptr = NULL;
+
        memprintf(&ptr, "Built with Lua version : %s", LUA_RELEASE);
        hap_register_build_opts(ptr, 1);
-       cfg_register_postparser("hlua", hlua_check_config);
 }
+
+INITCALL0(STG_REGISTER, hlua_register_build_options);
index 72f5079ebdb8646ddf32f0fa8638462b14869364..8a2e5a7b121eb40ae5f77fcc69216106f4318417 100644 (file)
@@ -106,8 +106,4 @@ int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol
        return sock;
 }
 
-__attribute__((constructor))
-static void __ns_init(void)
-{
-       hap_register_build_opts("Built with network namespace support.", 0);
-}
+REGISTER_BUILD_OPTS("Built with network namespace support.");
index 26926680fcfc7812a7c2984f6dcdf2d488a35294..0c531e6ec9d0554355bffcb15588188faf80fa36 100644 (file)
@@ -2032,30 +2032,26 @@ static struct action_kw_list http_res_actions = {ILH, {
 
 INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_actions);
 
-__attribute__((constructor))
-static void __tcp_protocol_init(void)
-{
-       hap_register_build_opts("Built with transparent proxy support using:"
+REGISTER_BUILD_OPTS("Built with transparent proxy support using:"
 #if defined(IP_TRANSPARENT)
-              " IP_TRANSPARENT"
+                   " IP_TRANSPARENT"
 #endif
 #if defined(IPV6_TRANSPARENT)
-              " IPV6_TRANSPARENT"
+                   " IPV6_TRANSPARENT"
 #endif
 #if defined(IP_FREEBIND)
-              " IP_FREEBIND"
+                   " IP_FREEBIND"
 #endif
 #if defined(IP_BINDANY)
-              " IP_BINDANY"
+                   " IP_BINDANY"
 #endif
 #if defined(IPV6_BINDANY)
-              " IPV6_BINDANY"
+                   " IPV6_BINDANY"
 #endif
 #if defined(SO_BINDANY)
-              " SO_BINDANY"
+                   " SO_BINDANY"
 #endif
-               "", 0);
-}
+                   "");
 
 
 /*
index f3f74c3dce485dee83f1c42598f86bcd947291f0..713f0c9875b63540171525c7f85928e4ec0fbb25 100644 (file)
@@ -411,8 +411,7 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **
        return 1;
 }
 
-__attribute__((constructor))
-static void __regex_init(void)
+static void regex_register_build_options(void)
 {
        char *ptr = NULL;
 
@@ -458,6 +457,8 @@ static void __regex_init(void)
        hap_register_build_opts(ptr, 1);
 }
 
+INITCALL0(STG_REGISTER, regex_register_build_options);
+
 /*
  * Local variables:
  *  c-indent-level: 8
index 3be4b2aedc09adf5527f53f005c2920fa6adab7b..86d4f227a47a77616043b160cc746669d8f66136 100644 (file)
@@ -9251,9 +9251,6 @@ static void ssl_sock_capture_free_func(void *parent, void *ptr, CRYPTO_EX_DATA *
 __attribute__((constructor))
 static void __ssl_sock_init(void)
 {
-       char *ptr;
-       int i;
-
        STACK_OF(SSL_COMP)* cm;
 
        if (global_ssl.listen_default_ciphers)
@@ -9288,7 +9285,26 @@ static void __ssl_sock_init(void)
        hap_register_post_check(tlskeys_finalize_config);
 #endif
 
-       ptr = NULL;
+       global.ssl_session_max_cost   = SSL_SESSION_MAX_COST;
+       global.ssl_handshake_max_cost = SSL_HANDSHAKE_MAX_COST;
+
+#ifndef OPENSSL_NO_DH
+       ssl_dh_ptr_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+       hap_register_post_deinit(ssl_free_dh);
+#endif
+#ifndef OPENSSL_NO_ENGINE
+       hap_register_post_deinit(ssl_free_engines);
+#endif
+       /* Load SSL string for the verbose & debug mode. */
+       ERR_load_SSL_strings();
+}
+
+/* Compute and register the version string */
+static void ssl_register_build_options()
+{
+       char *ptr = NULL;
+       int i;
+
        memprintf(&ptr, "Built with OpenSSL version : "
 #ifdef OPENSSL_IS_BORINGSSL
                "BoringSSL");
@@ -9326,20 +9342,10 @@ static void __ssl_sock_init(void)
                        memprintf(&ptr, "%s %s", ptr, methodVersions[i].name);
 
        hap_register_build_opts(ptr, 1);
+}
 
-       global.ssl_session_max_cost   = SSL_SESSION_MAX_COST;
-       global.ssl_handshake_max_cost = SSL_HANDSHAKE_MAX_COST;
+INITCALL0(STG_REGISTER, ssl_register_build_options);
 
-#ifndef OPENSSL_NO_DH
-       ssl_dh_ptr_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL, NULL);
-       hap_register_post_deinit(ssl_free_dh);
-#endif
-#ifndef OPENSSL_NO_ENGINE
-       hap_register_post_deinit(ssl_free_engines);
-#endif
-       /* Load SSL string for the verbose & debug mode. */
-       ERR_load_SSL_strings();
-}
 
 #ifndef OPENSSL_NO_ENGINE
 void ssl_free_engines(void) {
index eb1fb472dfb1cd86b435656d8ebdc9c09063bb79..cd6abef3698c259dc9bce96c940e7349f63530c0 100644 (file)
@@ -6,6 +6,7 @@
 #include <common/buffer.h>
 #include <common/errors.h>
 #include <common/initcall.h>
+#include <types/global.h>
 #include <proto/arg.h>
 #include <proto/log.h>
 #include <proto/proto_http.h>
@@ -693,8 +694,6 @@ INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 __attribute__((constructor))
 static void __wurfl_init(void)
 {
-       /* register sample fetch and format conversion keywords */
-       hap_register_build_opts("Built with WURFL support.", 0);
        hap_register_post_check(ha_wurfl_init);
        hap_register_post_deinit(ha_wurfl_deinit);
 }
@@ -802,3 +801,5 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void
        ha_wurfl_log("WURFL: retrieve header request returns [%s]\n", ((ha_wurfl_header_t *)wh)->header_value);
        return ((ha_wurfl_header_t *)wh)->header_value;
 }
+
+REGISTER_BUILD_OPTS("Built with WURFL support.");