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.
+ the configuration parser itself. At this step the final 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)())
local known to each compilation unit can will be appended into common lists at
boot time. This is why this call is placed just before STG_ALLOC.
+Note that trash is needed in various functions. Trash is a pool and is
+allocated during STG_POOL, so it's not permitted to use it before STG_INIT,
+where it will only use the default size, and may be reallocated later with a
+different size.
+
Example: register a very early call to init_log() with no argument, and another
call to cli_register_kw(&cli_kws) much later:
return 1;
}
+/* This is called during STG_POOL to allocate trash buffers early. They will
+ * be reallocated later once their final size is known. It returns 0 if an
+ * error occurred.
+ */
+static int alloc_early_trash(void)
+{
+ return init_trash_buffers(1);
+}
+
/*
* Does an snprintf() at the beginning of chunk <chk>, respecting the limit of
* at most chk->size chars. If the chk->len is over, nothing is added. Returns
return diff;
}
+INITCALL0(STG_POOL, alloc_early_trash);
REGISTER_PER_THREAD_ALLOC(alloc_trash_buffers_per_thread);
REGISTER_PER_THREAD_FREE(free_trash_buffers_per_thread);
REGISTER_POST_DEINIT(free_trash_buffers_per_thread);
startup_logs_init();
- if (!init_trash_buffers(1)) {
- ha_alert("failed to initialize trash buffers.\n");
- exit(1);
- }
-
if (init_acl() != 0)
exit(1);
RUN_INITCALLS(STG_ALLOC);
RUN_INITCALLS(STG_POOL);
+
+ /* some code really needs to have the trash properly allocated */
+ if (!trash.area) {
+ ha_alert("failed to initialize trash buffers.\n");
+ exit(1);
+ }
+
RUN_INITCALLS(STG_INIT);
/* this is the late init where the config is parsed */