]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: haproxy: add a registration for build options
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 17:43:10 +0000 (18:43 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 20:30:54 +0000 (21:30 +0100)
Many extensions now report some build options to ease debugging, but
this is now being done at the expense of code maintainability. Let's
provide a registration function to do this so that we can start to
remove most of the #ifdefs from haproxy.c (18 currently just for a
single function).

include/types/global.h
src/haproxy.c

index b32a09fc68027d830d10e6c427c5cfb2711cacd6..46d3951837bb935abb815377df356fa1f7c3f2e0 100644 (file)
@@ -264,6 +264,8 @@ static inline int already_warned(unsigned int warning)
        return 0;
 }
 
+void hap_register_build_opts(const char *str, int must_free);
+
 #endif /* _TYPES_GLOBAL_H */
 
 /*
index 14b4939ac42bf5d8cba32b287f1423f567b46a66..79844a38496a524e210eae901e70edbcbc9b7bf3 100644 (file)
@@ -267,10 +267,40 @@ static struct task *manage_global_listener_queue(struct task *t);
 /* bitfield of a few warnings to emit just once (WARN_*) */
 unsigned int warned = 0;
 
+
+/* These are strings to be reported in the output of "haproxy -vv". They may
+ * either be constants (in which case must_free must be zero) or dynamically
+ * allocated strings to pass to free() on exit, and in this case must_free
+ * must be non-zero.
+ */
+struct list build_opts_list = LIST_HEAD_INIT(build_opts_list);
+struct build_opts_str {
+       struct list list;
+       const char *str;
+       int must_free;
+};
+
 /*********************************************************************/
 /*  general purpose functions  ***************************************/
 /*********************************************************************/
 
+/* used to register some build option strings at boot. Set must_free to
+ * non-zero if the string must be freed upon exit.
+ */
+void hap_register_build_opts(const char *str, int must_free)
+{
+       struct build_opts_str *b;
+
+       b = calloc(1, sizeof(*b));
+       if (!b) {
+               fprintf(stderr, "out of memory\n");
+               exit(1);
+       }
+       b->str = str;
+       b->must_free = must_free;
+       LIST_ADDQ(&build_opts_list, &b->list);
+}
+
 static void display_version()
 {
        printf("HA-Proxy version " HAPROXY_VERSION " " HAPROXY_DATE"\n");
@@ -279,6 +309,8 @@ static void display_version()
 
 static void display_build_opts()
 {
+       struct build_opts_str *item;
+
        printf("Build options :"
 #ifdef BUILD_TARGET
               "\n  TARGET  = " BUILD_TARGET
@@ -435,6 +467,10 @@ static void display_build_opts()
 #ifdef USE_WURFL
        printf("Built with WURFL support\n");
 #endif
+       list_for_each_entry(item, &build_opts_list, list) {
+               puts(item->str);
+       }
+
        putchar('\n');
 
        list_pollers(stdout);
@@ -1376,6 +1412,7 @@ static void deinit(void)
        struct logsrv *log, *logb;
        struct logformat_node *lf, *lfb;
        struct bind_conf *bind_conf, *bind_back;
+       struct build_opts_str *bol, *bolb;
        int i;
 
        deinit_signals();
@@ -1680,6 +1717,13 @@ static void deinit(void)
                free(wl);
        }
 
+       list_for_each_entry_safe(bol, bolb, &build_opts_list, list) {
+               if (bol->must_free)
+                       free((void *)bol->str);
+               LIST_DEL(&bol->list);
+               free(bol);
+       }
+
        vars_prune(&global.vars, NULL, NULL);
 
        pool_destroy2(pool2_stream);