From: Willy Tarreau Date: Wed, 21 Dec 2016 19:46:26 +0000 (+0100) Subject: MINOR: haproxy: add a registration for post-deinit functions X-Git-Tag: v1.8-dev1~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05554e6bf187584fe653adf4791de3181b5a5c9c;p=thirdparty%2Fhaproxy.git MINOR: haproxy: add a registration for post-deinit functions 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. --- diff --git a/include/types/global.h b/include/types/global.h index 9bf77d3323..761d0b6535 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -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 */ diff --git a/src/haproxy.c b/src/haproxy.c index ef1b071d9b..06fc895528 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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;