MINOR: initcall: record the file and line declaration of an INITCALL

The INITCALL macros will now store the file and line number where they
are declared into the initcall struct, and RUN_INITCALLS() will assign
them to the global caller_file and caller_line variables, and will even
set caller_initcall to the current initall so that at any instant such
functions know where their caller declared them. This will help with
error messages and traces where a bit of context will be welcome.
This commit is contained in:
Willy Tarreau 2026-03-03 10:08:19 +01:00
parent 3f3a0609e3
commit 33c928c745
3 changed files with 32 additions and 2 deletions

View File

@ -20,6 +20,11 @@ extern struct list server_deinit_list;
extern struct list per_thread_free_list;
extern struct list per_thread_deinit_list;
/* initcall caller location */
extern const struct initcall *caller_initcall;
extern const char *caller_file;
extern int caller_line;
void hap_register_pre_check(int (*fct)());
void hap_register_post_check(int (*fct)());
void hap_register_post_proxy_check(int (*fct)(struct proxy *));

View File

@ -77,6 +77,8 @@ struct initcall {
void *arg1;
void *arg2;
void *arg3;
const char *loc_file; /* file where the call is declared, or NULL */
int loc_line; /* line where the call is declared, or NULL */
#if defined(USE_OBSOLETE_LINKER)
void *next;
#endif
@ -107,6 +109,8 @@ struct initcall {
.arg1 = (void *)(a1), \
.arg2 = (void *)(a2), \
.arg3 = (void *)(a3), \
.loc_file = __FILE__, \
.loc_line = linenum, \
} : NULL
@ -131,6 +135,8 @@ __attribute__((constructor)) static void __initcb_##linenum() \
.arg1 = (void *)(a1), \
.arg2 = (void *)(a2), \
.arg3 = (void *)(a3), \
.loc_file = __FILE__, \
.loc_line = linenum, \
}; \
if (stg < STG_SIZE) { \
entry.next = __initstg[stg]; \
@ -229,8 +235,15 @@ extern struct initcall *__initstg[STG_SIZE];
const struct initcall **ptr; \
if (stg >= STG_SIZE) \
break; \
FOREACH_INITCALL(ptr, stg) \
FOREACH_INITCALL(ptr, stg) { \
caller_initcall = *ptr; \
caller_file = (*ptr)->loc_file; \
caller_line = (*ptr)->loc_line; \
(*ptr)->fct((*ptr)->arg1, (*ptr)->arg2, (*ptr)->arg3); \
caller_initcall = NULL; \
caller_file = NULL; \
caller_line = 0; \
} \
} while (0)
#else // USE_OBSOLETE_LINKER
@ -243,8 +256,15 @@ extern struct initcall *__initstg[STG_SIZE];
const struct initcall *ptr; \
if (stg >= STG_SIZE) \
break; \
FOREACH_INITCALL(ptr, stg) \
FOREACH_INITCALL(ptr, stg) { \
caller_initcall = ptr; \
caller_file = (ptr)->loc_file; \
caller_line = (ptr)->loc_line; \
(ptr)->fct((ptr)->arg1, (ptr)->arg2, (ptr)->arg3); \
caller_initcall = NULL; \
caller_file = NULL; \
caller_line = 0; \
} \
} while (0)
#endif // USE_OBSOLETE_LINKER

View File

@ -89,6 +89,11 @@ struct list per_thread_free_list = LIST_HEAD_INIT(per_thread_free_list);
* valgrind mostly happy. */
struct list per_thread_deinit_list = LIST_HEAD_INIT(per_thread_deinit_list);
/* location of current INITCALL declaration being processed, or NULL */
const struct initcall *caller_initcall = NULL;
const char *caller_file = NULL;
int caller_line = 0;
/* used to register some initialization functions to call before the checks. */
void hap_register_pre_check(int (*fct)())
{