diff --git a/include/haproxy/init.h b/include/haproxy/init.h index 47333ffe4..91b46b0f9 100644 --- a/include/haproxy/init.h +++ b/include/haproxy/init.h @@ -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 *)); diff --git a/include/haproxy/initcall.h b/include/haproxy/initcall.h index a5f2bd2a8..39c43d7df 100644 --- a/include/haproxy/initcall.h +++ b/include/haproxy/initcall.h @@ -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 diff --git a/src/init.c b/src/init.c index ac5ac7a2e..de8b48da2 100644 --- a/src/init.c +++ b/src/init.c @@ -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)()) {