exit. See also hap_register_per_thread_alloc() for functions called before
these ones.
+- void hap_register_pre_check(int (*fct)())
+
+ This adds a call to function <fct> to the list of functions to be called at
+ the step just before the configuration validity checks. This is useful when you
+ need to create things like it would have been done during the configuration
+ parsing and where the initialization should continue in the configuration
+ check.
+ It could be used for example to generate a proxy with multiple servers using
+ the configuration parser itself. At this step the trash buffers are allocated.
+ Threads are not yet started so no protection is required. The function is
+ expected to return non-zero on success, or zero on failure. A failure will make
+ the process emit a succinct error message and immediately exit.
+
- void hap_register_post_check(int (*fct)())
This adds a call to function <fct> to the list of functions to be called at
create_pool_callback() with these arguments at stage STG_POOL. Do not use it
directly, use either DECLARE_POOL() or DECLARE_STATIC_POOL() instead.
+- REGISTER_PRE_CHECK(fct)
+
+ Registers a call to register_pre_check(fct) at stage STG_REGISTER.
+
- REGISTER_POST_CHECK(fct)
Registers a call to register_post_check(fct) at stage STG_REGISTER.
struct proxy;
struct server;
+struct pre_check_fct {
+ struct list list;
+ int (*fct)();
+};
+
struct post_check_fct {
struct list list;
int (*fct)();
struct proxy;
struct server;
+extern struct list pre_check_list;
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_free_list;
extern struct list per_thread_deinit_list;
+void hap_register_pre_check(int (*fct)());
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_per_thread_deinit(void (*fct)());
void hap_register_per_thread_free(void (*fct)());
+/* simplified way to declare a pre-check callback in a file */
+#define REGISTER_PRE_CHECK(fct) \
+ INITCALL1(STG_REGISTER, hap_register_pre_check, (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))
struct wordlist *wl;
struct proxy *px;
struct post_check_fct *pcf;
+ struct pre_check_fct *prcf;
int ideal_maxconn;
if (!init_trash_buffers(1)) {
/* destroy unreferenced defaults proxies */
proxy_destroy_all_unref_defaults();
+ list_for_each_entry(prcf, &pre_check_list, list)
+ err_code |= prcf->fct();
err_code |= check_config_validity();
for (px = proxies_list; px; px = px->next) {
#include <haproxy/init.h>
#include <haproxy/list.h>
+/* These functions are called just before a config validity check, which mean
+ * they are suited to use them in case we need to generate part of the
+ * configuration. It could be used for example to generate a proxy with
+ * multiple servers using the configuration parser itself. At this step the
+ * trash buffers are allocated.
+ * 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 pre_check_list = LIST_HEAD_INIT(pre_check_list);
+
/* 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
* valgrind mostly happy. */
struct list per_thread_deinit_list = LIST_HEAD_INIT(per_thread_deinit_list);
+/* used to register some initialization functions to call before the checks. */
+void hap_register_pre_check(int (*fct)())
+{
+ struct pre_check_fct *b;
+
+ b = calloc(1, sizeof(*b));
+ if (!b) {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+ b->fct = fct;
+ LIST_APPEND(&pre_check_list, &b->list);
+}
+
/* used to register some initialization functions to call after the checks. */
void hap_register_post_check(int (*fct)())
{