extern struct list per_thread_alloc_list;
extern struct list per_thread_init_list;
extern struct list post_deinit_list;
+extern struct list post_deinit_master_list;
extern struct list proxy_deinit_list;
extern struct list server_deinit_list;
extern struct list per_thread_free_list;
void hap_register_post_proxy_check(int (*fct)(struct proxy *));
void hap_register_post_server_check(int (*fct)(struct server *));
void hap_register_post_deinit(void (*fct)());
+void hap_register_post_deinit_master(void (*fct)());
void hap_register_proxy_deinit(void (*fct)(struct proxy *));
void hap_register_server_deinit(void (*fct)(struct server *));
#define REGISTER_POST_DEINIT(fct) \
INITCALL1(STG_REGISTER, hap_register_post_deinit, (fct))
+/* simplified way to declare a post-deinit (master process when launched in master/worker mode) callback in a file */
+#define REGISTER_POST_DEINIT_MASTER(fct) \
+ INITCALL1(STG_REGISTER, hap_register_post_deinit_master, (fct))
+
/* simplified way to declare a proxy-deinit callback in a file */
#define REGISTER_PROXY_DEINIT(fct) \
INITCALL1(STG_REGISTER, hap_register_proxy_deinit, (fct))
*/
struct list post_deinit_list = LIST_HEAD_INIT(post_deinit_list);
+/* These functions after everything is stopped, right before exit(), for the master
+ * process when haproxy was started in master-worker mode. They don't return anything.
+ */
+struct list post_deinit_master_list = LIST_HEAD_INIT(post_deinit_master_list);
+
/* These functions are called when freeing a proxy during the deinit, after
* everything isg stopped. They don't return anything. They should not release
* the proxy itself or any shared resources that are possibly used by other
LIST_APPEND(&post_deinit_list, &b->list);
}
+/* used to register some de-initialization functions to call after everything
+ * has stopped, but only for the master process (when started in master-worker mode).
+ */
+void hap_register_post_deinit_master(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_APPEND(&post_deinit_master_list, &b->list);
+}
+
/* used to register some per proxy de-initialization functions to call after
* everything has stopped.
*/
#include <haproxy/list.h>
#include <haproxy/log.h>
#include <haproxy/listener.h>
+#include <haproxy/list.h>
#include <haproxy/mworker.h>
#include <haproxy/peers.h>
#include <haproxy/proto_sockpair.h>
}
/* Better rely on the system than on a list of process to check if it was the last one */
else if (exitpid == -1 && errno == ECHILD) {
+ struct post_deinit_fct *pdff;
+
ha_warning("All workers exited. Exiting... (%d)\n", (exitcode > 0) ? exitcode : EXIT_SUCCESS);
+
+ list_for_each_entry(pdff, &post_deinit_master_list, list)
+ pdff->fct();
+
atexit_flag = 0;
if (exitcode > 0)
exit(exitcode); /* parent must leave using the status code that provoked the exit */