]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: haproxy: add a registration for post-deinit functions
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 19:46:26 +0000 (20:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 20:30:54 +0000 (21:30 +0100)
The 3 device detection engines stop at the same place in deinit()
with the usual #ifdefs. Similar to the other functions we can have
some late deinitialization functions. These functions do not return
anything however so we have to use a different type.

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

index 9bf77d332371b516d04bfd2770183ec50dccc62d..761d0b6535d2dfbe3a83b236c0c5f9ab46f92707 100644 (file)
@@ -266,6 +266,7 @@ static inline int already_warned(unsigned int warning)
 
 void hap_register_build_opts(const char *str, int must_free);
 void hap_register_post_check(int (*fct)());
+void hap_register_post_deinit(void (*fct)());
 
 #endif /* _TYPES_GLOBAL_H */
 
index ef1b071d9bc55d1f2e686d032d25098279099be3..06fc895528b1a62bc66e6b7ffe7800cb117935b5 100644 (file)
@@ -285,6 +285,17 @@ struct post_check_fct {
        int (*fct)();
 };
 
+/* These functions are called when freeing the global sections at the end
+ * of deinit, after everything is stopped. They don't return anything, and
+ * they work in best effort mode as their sole goal is to make valgrind
+ * mostly happy.
+ */
+struct list post_deinit_list = LIST_HEAD_INIT(post_deinit_list);
+struct post_deinit_fct {
+       struct list list;
+       void (*fct)();
+};
+
 /*********************************************************************/
 /*  general purpose functions  ***************************************/
 /*********************************************************************/
@@ -320,6 +331,22 @@ void hap_register_post_check(int (*fct)())
        LIST_ADDQ(&post_check_list, &b->list);
 }
 
+/* used to register some de-initialization functions to call after everything
+ * has stopped.
+ */
+void hap_register_post_deinit(void (*fct)())
+{
+       struct post_deinit_fct *b;
+
+       b = calloc(1, sizeof(*b));
+       if (!b) {
+               fprintf(stderr, "out of memory\n");
+               exit(1);
+       }
+       b->fct = fct;
+       LIST_ADDQ(&post_deinit_list, &b->list);
+}
+
 static void display_version()
 {
        printf("HA-Proxy version " HAPROXY_VERSION " " HAPROXY_DATE"\n");
@@ -1283,6 +1310,7 @@ static void deinit(void)
        struct logformat_node *lf, *lfb;
        struct bind_conf *bind_conf, *bind_back;
        struct build_opts_str *bol, *bolb;
+       struct post_deinit_fct *pdf;
        int i;
 
        deinit_signals();
@@ -1563,6 +1591,9 @@ static void deinit(void)
        ha_wurfl_deinit();
 #endif
 
+       list_for_each_entry(pdf, &post_deinit_list, list)
+               pdf->fct();
+
        free(global.log_send_hostname); global.log_send_hostname = NULL;
        chunk_destroy(&global.log_tag);
        free(global.chroot);  global.chroot = NULL;