mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
use RTLD_NOLOAD if it's available to make loading dynamic modules a little faster and less resource-intensive
also, keep trying to dlclose() a module until it actually goes away, since it may have other modules it brought in when it was loaded (thanks PCadach for pointing this problem out to me) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@40949 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -324,7 +324,7 @@ static struct ast_module *find_resource(const char *resource, int do_lock)
|
||||
static void unload_dynamic_module(struct ast_module *mod)
|
||||
{
|
||||
if (mod->lib)
|
||||
dlclose(mod->lib);
|
||||
while (!dlclose(mod->lib));
|
||||
/* WARNING: the structure pointed to by mod is now gone! */
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ static struct ast_module *load_dynamic_module(const char *resource_in, unsigned
|
||||
*/
|
||||
if (resource_being_loaded != (mod = AST_LIST_LAST(&module_list))) {
|
||||
/* no, it did not, so close it and return */
|
||||
dlclose(lib);
|
||||
while (!dlclose(lib));
|
||||
/* note that the module's destructor will call ast_module_unregister(),
|
||||
which will free the structure we allocated in resource_being_loaded */
|
||||
return NULL;
|
||||
@@ -376,15 +376,27 @@ static struct ast_module *load_dynamic_module(const char *resource_in, unsigned
|
||||
|
||||
wants_global = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);
|
||||
|
||||
/* we are done with this first load, so clean up and start over */
|
||||
|
||||
dlclose(lib);
|
||||
resource_being_loaded = NULL;
|
||||
|
||||
/* if we are being asked only to load modules that provide global symbols,
|
||||
and this one does not, then close it and return */
|
||||
if (global_symbols_only && !wants_global)
|
||||
if (global_symbols_only && !wants_global) {
|
||||
while (!dlclose(lib));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* if the system supports RTLD_NOLOAD, we can just 'promote' the flags
|
||||
on the already-opened library to what we want... if not, we have to
|
||||
close it and start over
|
||||
*/
|
||||
#if HAVE_RTLD_NOLOAD
|
||||
if (!dlopen(fn, RTLD_NOLOAD | (wants_global ? RTLD_GLOBAL : RTLD_NOW))) {
|
||||
ast_log(LOG_WARNING, "%s\n", dlerror());
|
||||
while (!dlclose(lib));
|
||||
free(resource_being_loaded);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
while (!dlclose(lib));
|
||||
resource_being_loaded = NULL;
|
||||
|
||||
/* start the load process again */
|
||||
|
||||
@@ -402,6 +414,8 @@ static struct ast_module *load_dynamic_module(const char *resource_in, unsigned
|
||||
/* since the module was successfully opened, and it registered itself
|
||||
the previous time we did that, we're going to assume it worked this
|
||||
time too :) */
|
||||
#endif
|
||||
|
||||
AST_LIST_LAST(&module_list)->lib = lib;
|
||||
resource_being_loaded = NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user