mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
REORG: global: move initcall register code in a dedicated file
Create a new module init which contains code related to REGISTER_* macros for initcalls. init.h is included in api.h to make init code available to all modules. It's a step to clean up a bit haproxy.c/global.h.
This commit is contained in:
parent
df627943a4
commit
ce44482fe5
2
Makefile
2
Makefile
@ -878,7 +878,7 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/http_ana.o src/stream.o \
|
|||||||
src/ebistree.o src/auth.o src/wdt.o src/http_acl.o \
|
src/ebistree.o src/auth.o src/wdt.o src/http_acl.o \
|
||||||
src/hpack-enc.o src/hpack-huff.o src/ebtree.o src/base64.o \
|
src/hpack-enc.o src/hpack-huff.o src/ebtree.o src/base64.o \
|
||||||
src/hash.o src/dgram.o src/version.o src/fix.o src/mqtt.o src/dns.o \
|
src/hash.o src/dgram.o src/version.o src/fix.o src/mqtt.o src/dns.o \
|
||||||
src/server_state.o src/proto_uxdg.o
|
src/server_state.o src/proto_uxdg.o src/init.o
|
||||||
|
|
||||||
ifneq ($(TRACE),)
|
ifneq ($(TRACE),)
|
||||||
OBJS += src/calltrace.o
|
OBJS += src/calltrace.o
|
||||||
|
@ -33,6 +33,6 @@
|
|||||||
#include <haproxy/api-t.h>
|
#include <haproxy/api-t.h>
|
||||||
#include <haproxy/atomic.h>
|
#include <haproxy/atomic.h>
|
||||||
#include <haproxy/bug.h>
|
#include <haproxy/bug.h>
|
||||||
#include <haproxy/initcall.h>
|
#include <haproxy/init.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,17 +66,6 @@ void run_poll_loop(void);
|
|||||||
int tell_old_pids(int sig);
|
int tell_old_pids(int sig);
|
||||||
int delete_oldpid(int pid);
|
int delete_oldpid(int pid);
|
||||||
void hap_register_build_opts(const char *str, int must_free);
|
void hap_register_build_opts(const char *str, int must_free);
|
||||||
void hap_register_post_check(int (*fct)());
|
|
||||||
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_proxy_deinit(void (*fct)(struct proxy *));
|
|
||||||
void hap_register_server_deinit(void (*fct)(struct server *));
|
|
||||||
|
|
||||||
void hap_register_per_thread_alloc(int (*fct)());
|
|
||||||
void hap_register_per_thread_init(int (*fct)());
|
|
||||||
void hap_register_per_thread_deinit(void (*fct)());
|
|
||||||
void hap_register_per_thread_free(void (*fct)());
|
|
||||||
|
|
||||||
void mworker_accept_wrapper(int fd);
|
void mworker_accept_wrapper(int fd);
|
||||||
void mworker_reload();
|
void mworker_reload();
|
||||||
@ -106,46 +95,6 @@ static inline unsigned long thread_mask(unsigned long mask)
|
|||||||
#define REGISTER_BUILD_OPTS(str) \
|
#define REGISTER_BUILD_OPTS(str) \
|
||||||
INITCALL2(STG_REGISTER, hap_register_build_opts, (str), 0)
|
INITCALL2(STG_REGISTER, hap_register_build_opts, (str), 0)
|
||||||
|
|
||||||
/* simplified way to declare a post-check callback in a file */
|
|
||||||
#define REGISTER_POST_CHECK(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_post_check, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a post-proxy-check callback in a file */
|
|
||||||
#define REGISTER_POST_PROXY_CHECK(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_post_proxy_check, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a post-server-check callback in a file */
|
|
||||||
#define REGISTER_POST_SERVER_CHECK(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_post_server_check, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a post-deinit callback in a file */
|
|
||||||
#define REGISTER_POST_DEINIT(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_post_deinit, (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))
|
|
||||||
|
|
||||||
/* simplified way to declare a proxy-deinit callback in a file */
|
|
||||||
#define REGISTER_SERVER_DEINIT(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_server_deinit, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a per-thread allocation callback in a file */
|
|
||||||
#define REGISTER_PER_THREAD_ALLOC(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_per_thread_alloc, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a per-thread init callback in a file */
|
|
||||||
#define REGISTER_PER_THREAD_INIT(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_per_thread_init, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a per-thread deinit callback in a file */
|
|
||||||
#define REGISTER_PER_THREAD_DEINIT(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_per_thread_deinit, (fct))
|
|
||||||
|
|
||||||
/* simplified way to declare a per-thread free callback in a file */
|
|
||||||
#define REGISTER_PER_THREAD_FREE(fct) \
|
|
||||||
INITCALL1(STG_REGISTER, hap_register_per_thread_free, (fct))
|
|
||||||
|
|
||||||
#endif /* _HAPROXY_GLOBAL_H */
|
#endif /* _HAPROXY_GLOBAL_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
59
include/haproxy/init-t.h
Normal file
59
include/haproxy/init-t.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#ifndef _HAPROXY_INIT_T_H
|
||||||
|
#define _HAPROXY_INIT_T_H
|
||||||
|
|
||||||
|
#include <haproxy/list-t.h>
|
||||||
|
|
||||||
|
struct proxy;
|
||||||
|
struct server;
|
||||||
|
|
||||||
|
struct post_check_fct {
|
||||||
|
struct list list;
|
||||||
|
int (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct post_proxy_check_fct {
|
||||||
|
struct list list;
|
||||||
|
int (*fct)(struct proxy *);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct post_server_check_fct {
|
||||||
|
struct list list;
|
||||||
|
int (*fct)(struct server *);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct per_thread_alloc_fct {
|
||||||
|
struct list list;
|
||||||
|
int (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct per_thread_init_fct {
|
||||||
|
struct list list;
|
||||||
|
int (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct post_deinit_fct {
|
||||||
|
struct list list;
|
||||||
|
void (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct proxy_deinit_fct {
|
||||||
|
struct list list;
|
||||||
|
void (*fct)(struct proxy *);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct server_deinit_fct {
|
||||||
|
struct list list;
|
||||||
|
void (*fct)(struct server *);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct per_thread_free_fct {
|
||||||
|
struct list list;
|
||||||
|
void (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct per_thread_deinit_fct {
|
||||||
|
struct list list;
|
||||||
|
void (*fct)();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _HAPROXY_INIT_T_H */
|
73
include/haproxy/init.h
Normal file
73
include/haproxy/init.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#ifndef _HAPROXY_INIT_H
|
||||||
|
#define _HAPROXY_INIT_H
|
||||||
|
|
||||||
|
#include <haproxy/init-t.h>
|
||||||
|
#include <haproxy/initcall.h>
|
||||||
|
|
||||||
|
struct proxy;
|
||||||
|
struct server;
|
||||||
|
|
||||||
|
extern struct list post_check_list;
|
||||||
|
extern struct list post_proxy_check_list;
|
||||||
|
extern struct list post_server_check_list;
|
||||||
|
extern struct list per_thread_alloc_list;
|
||||||
|
extern struct list per_thread_init_list;
|
||||||
|
extern struct list post_deinit_list;
|
||||||
|
extern struct list proxy_deinit_list;
|
||||||
|
extern struct list server_deinit_list;
|
||||||
|
extern struct list per_thread_free_list;
|
||||||
|
extern struct list per_thread_deinit_list;
|
||||||
|
|
||||||
|
void hap_register_post_check(int (*fct)());
|
||||||
|
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_proxy_deinit(void (*fct)(struct proxy *));
|
||||||
|
void hap_register_server_deinit(void (*fct)(struct server *));
|
||||||
|
|
||||||
|
void hap_register_per_thread_alloc(int (*fct)());
|
||||||
|
void hap_register_per_thread_init(int (*fct)());
|
||||||
|
void hap_register_per_thread_deinit(void (*fct)());
|
||||||
|
void hap_register_per_thread_free(void (*fct)());
|
||||||
|
|
||||||
|
/* simplified way to declare a post-check callback in a file */
|
||||||
|
#define REGISTER_POST_CHECK(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_post_check, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a post-proxy-check callback in a file */
|
||||||
|
#define REGISTER_POST_PROXY_CHECK(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_post_proxy_check, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a post-server-check callback in a file */
|
||||||
|
#define REGISTER_POST_SERVER_CHECK(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_post_server_check, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a post-deinit callback in a file */
|
||||||
|
#define REGISTER_POST_DEINIT(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_post_deinit, (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))
|
||||||
|
|
||||||
|
/* simplified way to declare a proxy-deinit callback in a file */
|
||||||
|
#define REGISTER_SERVER_DEINIT(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_server_deinit, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a per-thread allocation callback in a file */
|
||||||
|
#define REGISTER_PER_THREAD_ALLOC(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_per_thread_alloc, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a per-thread init callback in a file */
|
||||||
|
#define REGISTER_PER_THREAD_INIT(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_per_thread_init, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a per-thread deinit callback in a file */
|
||||||
|
#define REGISTER_PER_THREAD_DEINIT(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_per_thread_deinit, (fct))
|
||||||
|
|
||||||
|
/* simplified way to declare a per-thread free callback in a file */
|
||||||
|
#define REGISTER_PER_THREAD_FREE(fct) \
|
||||||
|
INITCALL1(STG_REGISTER, hap_register_per_thread_free, (fct))
|
||||||
|
|
||||||
|
#endif /* _HAPROXY_INIT_H */
|
@ -17,7 +17,6 @@
|
|||||||
#include <haproxy/errors.h>
|
#include <haproxy/errors.h>
|
||||||
#include <haproxy/fcgi-app.h>
|
#include <haproxy/fcgi-app.h>
|
||||||
#include <haproxy/filters.h>
|
#include <haproxy/filters.h>
|
||||||
#include <haproxy/global.h>
|
|
||||||
#include <haproxy/http_fetch.h>
|
#include <haproxy/http_fetch.h>
|
||||||
#include <haproxy/http_htx.h>
|
#include <haproxy/http_htx.h>
|
||||||
#include <haproxy/log.h>
|
#include <haproxy/log.h>
|
||||||
|
260
src/haproxy.c
260
src/haproxy.c
@ -252,115 +252,6 @@ struct build_opts_str {
|
|||||||
int must_free;
|
int must_free;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* These functions are called just after the point where the program exits
|
|
||||||
* after a config validity check, so they are generally suited for resource
|
|
||||||
* allocation and slow initializations that should be skipped during basic
|
|
||||||
* config checks. The functions must return 0 on success, or a combination
|
|
||||||
* of ERR_* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause
|
|
||||||
* and immediate exit, so the function must have emitted any useful error.
|
|
||||||
*/
|
|
||||||
struct list post_check_list = LIST_HEAD_INIT(post_check_list);
|
|
||||||
struct post_check_fct {
|
|
||||||
struct list list;
|
|
||||||
int (*fct)();
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called for each proxy just after the config validity
|
|
||||||
* check. The functions must return 0 on success, or a combination of ERR_*
|
|
||||||
* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause and immediate
|
|
||||||
* exit, so the function must have emitted any useful error.
|
|
||||||
*/
|
|
||||||
struct list post_proxy_check_list = LIST_HEAD_INIT(post_proxy_check_list);
|
|
||||||
struct post_proxy_check_fct {
|
|
||||||
struct list list;
|
|
||||||
int (*fct)(struct proxy *);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called for each server just after the config validity
|
|
||||||
* check. The functions must return 0 on success, or a combination of ERR_*
|
|
||||||
* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause and immediate
|
|
||||||
* exit, so the function must have emitted any useful error.
|
|
||||||
*/
|
|
||||||
struct list post_server_check_list = LIST_HEAD_INIT(post_server_check_list);
|
|
||||||
struct post_server_check_fct {
|
|
||||||
struct list list;
|
|
||||||
int (*fct)(struct server *);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called for each thread just after the thread creation
|
|
||||||
* and before running the init functions. They should be used to do per-thread
|
|
||||||
* (re-)allocations that are needed by subsequent functoins. They must return 0
|
|
||||||
* if an error occurred. */
|
|
||||||
struct list per_thread_alloc_list = LIST_HEAD_INIT(per_thread_alloc_list);
|
|
||||||
struct per_thread_alloc_fct {
|
|
||||||
struct list list;
|
|
||||||
int (*fct)();
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called for each thread just after the thread creation
|
|
||||||
* and before running the scheduler. They should be used to do per-thread
|
|
||||||
* initializations. They must return 0 if an error occurred. */
|
|
||||||
struct list per_thread_init_list = LIST_HEAD_INIT(per_thread_init_list);
|
|
||||||
struct per_thread_init_fct {
|
|
||||||
struct list list;
|
|
||||||
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. They should
|
|
||||||
* not release shared resources that are possibly used by other deinit
|
|
||||||
* functions, only close/release what is private. Use the per_thread_free_list
|
|
||||||
* to release shared resources.
|
|
||||||
*/
|
|
||||||
struct list post_deinit_list = LIST_HEAD_INIT(post_deinit_list);
|
|
||||||
struct post_deinit_fct {
|
|
||||||
struct list list;
|
|
||||||
void (*fct)();
|
|
||||||
};
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
* deinit functions, only close/release what is private.
|
|
||||||
*/
|
|
||||||
struct list proxy_deinit_list = LIST_HEAD_INIT(proxy_deinit_list);
|
|
||||||
struct proxy_deinit_fct {
|
|
||||||
struct list list;
|
|
||||||
void (*fct)(struct proxy *);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called when freeing a server 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
|
|
||||||
* deinit functions, only close/release what is private.
|
|
||||||
*/
|
|
||||||
struct list server_deinit_list = LIST_HEAD_INIT(server_deinit_list);
|
|
||||||
struct server_deinit_fct {
|
|
||||||
struct list list;
|
|
||||||
void (*fct)(struct server *);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called when freeing the global sections at the end of
|
|
||||||
* deinit, after the thread deinit functions, to release unneeded memory
|
|
||||||
* allocations. They don't return anything, and they work in best effort mode
|
|
||||||
* as their sole goal is to make valgrind mostly happy.
|
|
||||||
*/
|
|
||||||
struct list per_thread_free_list = LIST_HEAD_INIT(per_thread_free_list);
|
|
||||||
struct per_thread_free_fct {
|
|
||||||
struct list list;
|
|
||||||
void (*fct)();
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These functions are called for each thread just after the scheduler loop and
|
|
||||||
* before exiting the thread. They don't return anything and, as for post-deinit
|
|
||||||
* functions, they work in best effort mode as their sole goal is to make
|
|
||||||
* valgrind mostly happy. */
|
|
||||||
struct list per_thread_deinit_list = LIST_HEAD_INIT(per_thread_deinit_list);
|
|
||||||
struct per_thread_deinit_fct {
|
|
||||||
struct list list;
|
|
||||||
void (*fct)();
|
|
||||||
};
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/* general purpose functions ***************************************/
|
/* general purpose functions ***************************************/
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
@ -382,157 +273,6 @@ void hap_register_build_opts(const char *str, int must_free)
|
|||||||
LIST_ADDQ(&build_opts_list, &b->list);
|
LIST_ADDQ(&build_opts_list, &b->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* used to register some initialization functions to call after the checks. */
|
|
||||||
void hap_register_post_check(int (*fct)())
|
|
||||||
{
|
|
||||||
struct post_check_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&post_check_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some initialization functions to call for each proxy after
|
|
||||||
* the checks.
|
|
||||||
*/
|
|
||||||
void hap_register_post_proxy_check(int (*fct)(struct proxy *))
|
|
||||||
{
|
|
||||||
struct post_proxy_check_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&post_proxy_check_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some initialization functions to call for each server after
|
|
||||||
* the checks.
|
|
||||||
*/
|
|
||||||
void hap_register_post_server_check(int (*fct)(struct server *))
|
|
||||||
{
|
|
||||||
struct post_server_check_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&post_server_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some per proxy de-initialization functions to call after
|
|
||||||
* everything has stopped.
|
|
||||||
*/
|
|
||||||
void hap_register_proxy_deinit(void (*fct)(struct proxy *))
|
|
||||||
{
|
|
||||||
struct proxy_deinit_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&proxy_deinit_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* used to register some per server de-initialization functions to call after
|
|
||||||
* everything has stopped.
|
|
||||||
*/
|
|
||||||
void hap_register_server_deinit(void (*fct)(struct server *))
|
|
||||||
{
|
|
||||||
struct server_deinit_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&server_deinit_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some allocation functions to call for each thread. */
|
|
||||||
void hap_register_per_thread_alloc(int (*fct)())
|
|
||||||
{
|
|
||||||
struct per_thread_alloc_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&per_thread_alloc_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some initialization functions to call for each thread. */
|
|
||||||
void hap_register_per_thread_init(int (*fct)())
|
|
||||||
{
|
|
||||||
struct per_thread_init_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&per_thread_init_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some de-initialization functions to call for each thread. */
|
|
||||||
void hap_register_per_thread_deinit(void (*fct)())
|
|
||||||
{
|
|
||||||
struct per_thread_deinit_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&per_thread_deinit_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* used to register some free functions to call for each thread. */
|
|
||||||
void hap_register_per_thread_free(void (*fct)())
|
|
||||||
{
|
|
||||||
struct per_thread_free_fct *b;
|
|
||||||
|
|
||||||
b = calloc(1, sizeof(*b));
|
|
||||||
if (!b) {
|
|
||||||
fprintf(stderr, "out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
b->fct = fct;
|
|
||||||
LIST_ADDQ(&per_thread_free_list, &b->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void display_version()
|
static void display_version()
|
||||||
{
|
{
|
||||||
struct utsname utsname;
|
struct utsname utsname;
|
||||||
|
224
src/init.c
Normal file
224
src/init.c
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <haproxy/init.h>
|
||||||
|
#include <haproxy/list.h>
|
||||||
|
|
||||||
|
/* These functions are called just after the point where the program exits
|
||||||
|
* after a config validity check, so they are generally suited for resource
|
||||||
|
* allocation and slow initializations that should be skipped during basic
|
||||||
|
* config checks. The functions must return 0 on success, or a combination
|
||||||
|
* of ERR_* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause
|
||||||
|
* and immediate exit, so the function must have emitted any useful error.
|
||||||
|
*/
|
||||||
|
struct list post_check_list = LIST_HEAD_INIT(post_check_list);
|
||||||
|
|
||||||
|
/* These functions are called for each proxy just after the config validity
|
||||||
|
* check. The functions must return 0 on success, or a combination of ERR_*
|
||||||
|
* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause and immediate
|
||||||
|
* exit, so the function must have emitted any useful error.
|
||||||
|
*/
|
||||||
|
struct list post_proxy_check_list = LIST_HEAD_INIT(post_proxy_check_list);
|
||||||
|
|
||||||
|
/* These functions are called for each server just after the config validity
|
||||||
|
* check. The functions must return 0 on success, or a combination of ERR_*
|
||||||
|
* flags (ERR_WARN, ERR_ABORT, ERR_FATAL, ...). The 2 latter cause and immediate
|
||||||
|
* exit, so the function must have emitted any useful error.
|
||||||
|
*/
|
||||||
|
struct list post_server_check_list = LIST_HEAD_INIT(post_server_check_list);
|
||||||
|
|
||||||
|
/* These functions are called for each thread just after the thread creation
|
||||||
|
* and before running the init functions. They should be used to do per-thread
|
||||||
|
* (re-)allocations that are needed by subsequent functoins. They must return 0
|
||||||
|
* if an error occurred. */
|
||||||
|
struct list per_thread_alloc_list = LIST_HEAD_INIT(per_thread_alloc_list);
|
||||||
|
|
||||||
|
/* These functions are called for each thread just after the thread creation
|
||||||
|
* and before running the scheduler. They should be used to do per-thread
|
||||||
|
* initializations. They must return 0 if an error occurred. */
|
||||||
|
struct list per_thread_init_list = LIST_HEAD_INIT(per_thread_init_list);
|
||||||
|
|
||||||
|
/* These functions are called when freeing the global sections at the end of
|
||||||
|
* deinit, after everything is stopped. They don't return anything. They should
|
||||||
|
* not release shared resources that are possibly used by other deinit
|
||||||
|
* functions, only close/release what is private. Use the per_thread_free_list
|
||||||
|
* to release shared resources.
|
||||||
|
*/
|
||||||
|
struct list post_deinit_list = LIST_HEAD_INIT(post_deinit_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
|
||||||
|
* deinit functions, only close/release what is private.
|
||||||
|
*/
|
||||||
|
struct list proxy_deinit_list = LIST_HEAD_INIT(proxy_deinit_list);
|
||||||
|
|
||||||
|
/* These functions are called when freeing a server 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
|
||||||
|
* deinit functions, only close/release what is private.
|
||||||
|
*/
|
||||||
|
struct list server_deinit_list = LIST_HEAD_INIT(server_deinit_list);
|
||||||
|
|
||||||
|
/* These functions are called when freeing the global sections at the end of
|
||||||
|
* deinit, after the thread deinit functions, to release unneeded memory
|
||||||
|
* allocations. They don't return anything, and they work in best effort mode
|
||||||
|
* as their sole goal is to make valgrind mostly happy.
|
||||||
|
*/
|
||||||
|
struct list per_thread_free_list = LIST_HEAD_INIT(per_thread_free_list);
|
||||||
|
|
||||||
|
/* These functions are called for each thread just after the scheduler loop and
|
||||||
|
* before exiting the thread. They don't return anything and, as for post-deinit
|
||||||
|
* functions, they work in best effort mode as their sole goal is to make
|
||||||
|
* valgrind mostly happy. */
|
||||||
|
struct list per_thread_deinit_list = LIST_HEAD_INIT(per_thread_deinit_list);
|
||||||
|
|
||||||
|
/* used to register some initialization functions to call after the checks. */
|
||||||
|
void hap_register_post_check(int (*fct)())
|
||||||
|
{
|
||||||
|
struct post_check_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&post_check_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some initialization functions to call for each proxy after
|
||||||
|
* the checks.
|
||||||
|
*/
|
||||||
|
void hap_register_post_proxy_check(int (*fct)(struct proxy *))
|
||||||
|
{
|
||||||
|
struct post_proxy_check_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&post_proxy_check_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some initialization functions to call for each server after
|
||||||
|
* the checks.
|
||||||
|
*/
|
||||||
|
void hap_register_post_server_check(int (*fct)(struct server *))
|
||||||
|
{
|
||||||
|
struct post_server_check_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&post_server_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some per proxy de-initialization functions to call after
|
||||||
|
* everything has stopped.
|
||||||
|
*/
|
||||||
|
void hap_register_proxy_deinit(void (*fct)(struct proxy *))
|
||||||
|
{
|
||||||
|
struct proxy_deinit_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&proxy_deinit_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some per server de-initialization functions to call after
|
||||||
|
* everything has stopped.
|
||||||
|
*/
|
||||||
|
void hap_register_server_deinit(void (*fct)(struct server *))
|
||||||
|
{
|
||||||
|
struct server_deinit_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&server_deinit_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some allocation functions to call for each thread. */
|
||||||
|
void hap_register_per_thread_alloc(int (*fct)())
|
||||||
|
{
|
||||||
|
struct per_thread_alloc_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&per_thread_alloc_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some initialization functions to call for each thread. */
|
||||||
|
void hap_register_per_thread_init(int (*fct)())
|
||||||
|
{
|
||||||
|
struct per_thread_init_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&per_thread_init_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some de-initialization functions to call for each thread. */
|
||||||
|
void hap_register_per_thread_deinit(void (*fct)())
|
||||||
|
{
|
||||||
|
struct per_thread_deinit_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&per_thread_deinit_list, &b->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* used to register some free functions to call for each thread. */
|
||||||
|
void hap_register_per_thread_free(void (*fct)())
|
||||||
|
{
|
||||||
|
struct per_thread_free_fct *b;
|
||||||
|
|
||||||
|
b = calloc(1, sizeof(*b));
|
||||||
|
if (!b) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
b->fct = fct;
|
||||||
|
LIST_ADDQ(&per_thread_free_list, &b->list);
|
||||||
|
}
|
@ -28,7 +28,6 @@
|
|||||||
#include <haproxy/dns.h>
|
#include <haproxy/dns.h>
|
||||||
#include <haproxy/errors.h>
|
#include <haproxy/errors.h>
|
||||||
#include <haproxy/fd.h>
|
#include <haproxy/fd.h>
|
||||||
#include <haproxy/global.h>
|
|
||||||
#include <haproxy/http_rules.h>
|
#include <haproxy/http_rules.h>
|
||||||
#include <haproxy/log.h>
|
#include <haproxy/log.h>
|
||||||
#include <haproxy/net_helper.h>
|
#include <haproxy/net_helper.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user