From: Arran Cudbard-Bell Date: Thu, 2 Jun 2022 17:10:31 +0000 (-0400) Subject: Move global_lib_init and instantiation calls inside the module code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=812d3bc560a44b1e0cfbb491ec44572e1b5ae116;p=thirdparty%2Ffreeradius-server.git Move global_lib_init and instantiation calls inside the module code --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index 97712cadfc1..a9e502a2d57 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -573,21 +573,11 @@ int main(int argc, char *argv[]) EXIT_WITH_FAILURE; } - /* - * Setup the global structure for libraries - */ - if (global_lib_init() < 0) EXIT_WITH_FAILURE; - /* * Read the configuration files, BEFORE doing anything else. */ if (main_config_init(config) < 0) EXIT_WITH_FAILURE; - /* - * Instantiate any libraries loaded by config parsing - */ - if (global_lib_instantiate() < 0) EXIT_WITH_FAILURE; - /* * Check we're the only process using this config. */ diff --git a/src/lib/server/global_lib.c b/src/lib/server/global_lib.c index a4d11eb2516..8cc37a3e4da 100644 --- a/src/lib/server/global_lib.c +++ b/src/lib/server/global_lib.c @@ -203,6 +203,8 @@ static int _lib_list_free_atexit(UNUSED void *uctx) */ int global_lib_init(void) { + if (lib_list) return; + MEM(lib_list = talloc_zero(NULL, global_lib_list_t)); fr_rb_inline_init(&lib_list->libs, global_lib_inst_t, entry, _lib_cmp, NULL); diff --git a/src/lib/server/module.c b/src/lib/server/module.c index c598f081080..ee7e09e5b08 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -1106,10 +1106,17 @@ static void _module_global_list_init(void *uctx) { dl_modules = dl_module_loader_init(uctx); MEM(module_global_inst_list = fr_heap_alloc(NULL, _module_instance_global_cmp, module_instance_t, inst_idx, 256)); + + /* + * Ensure the common library tracking + * tree is in place... + */ + global_lib_init(); } static int _module_global_list_free(UNUSED void *uctx) { + if (!fr_cond_assert_msg(fr_heap_num_elements(module_global_inst_list) == 0, "Global module heap has %u elements remaining on exit. This is a leak", fr_heap_num_elements(module_global_inst_list))) return -1; diff --git a/src/lib/server/module_rlm.c b/src/lib/server/module_rlm.c index a9e01f6a35f..158325ecee2 100644 --- a/src/lib/server/module_rlm.c +++ b/src/lib/server/module_rlm.c @@ -1005,6 +1005,12 @@ int modules_rlm_bootstrap(CONF_SECTION *root) module_rlm_virtual_t *vm; fr_rb_iter_inorder_t iter; CONF_SECTION *actions; + + /* + * Ensure any libraries the modules depend on are instantiated + */ + global_lib_instantiate(); + /* * Remember where the modules were stored. */ diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index d748bd83e59..54e9f42672e 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -1277,6 +1277,11 @@ int virtual_servers_bootstrap(CONF_SECTION *config) { virtual_server_root = config; + /* + * Ensure any libraries the modules depend on are instantiated + */ + global_lib_instantiate(); + if (modules_bootstrap(process_modules) < 0) return -1; if (modules_bootstrap(proto_modules) < 0) return -1;