Merged revisions 62986 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r62986 | kpfleming | 2007-05-03 11:38:56 -0500 (Thu, 03 May 2007) | 2 lines improve loader a bit, by avoiding trying to initialize embedded modules twice and avoiding trying to load modules from disk when they have been loaded already during the 'preload' pass (reported by blitzrage on IRC, patch by me) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@62988 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
1e3b1a576c
commit
431b4a44d0
|
@ -80,17 +80,15 @@ static unsigned int embedding = 1; /* we always start out by registering embedde
|
||||||
since they are here before we dlopen() any
|
since they are here before we dlopen() any
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum flags {
|
|
||||||
FLAG_RUNNING = (1 << 1), /* module successfully initialized */
|
|
||||||
FLAG_DECLINED = (1 << 2), /* module declined to initialize */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ast_module {
|
struct ast_module {
|
||||||
const struct ast_module_info *info;
|
const struct ast_module_info *info;
|
||||||
void *lib; /* the shared lib, or NULL if embedded */
|
void *lib; /* the shared lib, or NULL if embedded */
|
||||||
int usecount; /* the number of 'users' currently in this module */
|
int usecount; /* the number of 'users' currently in this module */
|
||||||
struct module_user_list users; /* the list of users in the module */
|
struct module_user_list users; /* the list of users in the module */
|
||||||
unsigned int flags; /* flags for this module */
|
struct {
|
||||||
|
unsigned int running:1;
|
||||||
|
unsigned int declined:1;
|
||||||
|
} flags;
|
||||||
AST_LIST_ENTRY(ast_module) entry;
|
AST_LIST_ENTRY(ast_module) entry;
|
||||||
char resource[0];
|
char resource[0];
|
||||||
};
|
};
|
||||||
|
@ -443,7 +441,7 @@ int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode f
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ast_test_flag(mod, FLAG_RUNNING | FLAG_DECLINED))
|
if (!(mod->flags.running || mod->flags.declined))
|
||||||
error = 1;
|
error = 1;
|
||||||
|
|
||||||
if (!error && (mod->usecount > 0)) {
|
if (!error && (mod->usecount > 0)) {
|
||||||
|
@ -471,7 +469,7 @@ int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode f
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
ast_clear_flag(mod, FLAG_RUNNING | FLAG_DECLINED);
|
mod->flags.running = mod->flags.declined = 0;
|
||||||
|
|
||||||
AST_LIST_UNLOCK(&module_list);
|
AST_LIST_UNLOCK(&module_list);
|
||||||
|
|
||||||
|
@ -551,7 +549,7 @@ int ast_module_reload(const char *name)
|
||||||
if (name && resource_name_match(name, cur->resource))
|
if (name && resource_name_match(name, cur->resource))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!ast_test_flag(cur, FLAG_RUNNING | FLAG_DECLINED))
|
if (!(cur->flags.running || cur->flags.declined))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!info->reload) { /* cannot be reloaded */
|
if (!info->reload) { /* cannot be reloaded */
|
||||||
|
@ -599,7 +597,7 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
|
|
||||||
if ((mod = find_resource(resource_name, 0))) {
|
if ((mod = find_resource(resource_name, 0))) {
|
||||||
if (ast_test_flag(mod, FLAG_RUNNING)) {
|
if (mod->flags.running) {
|
||||||
ast_log(LOG_WARNING, "Module '%s' already exists.\n", resource_name);
|
ast_log(LOG_WARNING, "Module '%s' already exists.\n", resource_name);
|
||||||
return AST_MODULE_LOAD_DECLINE;
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
}
|
}
|
||||||
|
@ -635,7 +633,7 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
|
||||||
return AST_MODULE_LOAD_DECLINE;
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_clear_flag(mod, FLAG_DECLINED);
|
mod->flags.declined = 0;
|
||||||
|
|
||||||
if (mod->info->load)
|
if (mod->info->load)
|
||||||
res = mod->info->load();
|
res = mod->info->load();
|
||||||
|
@ -652,12 +650,12 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
|
||||||
ast_verbose(VERBOSE_PREFIX_1 "Loaded %s => (%s)\n", resource_name, mod->info->description);
|
ast_verbose(VERBOSE_PREFIX_1 "Loaded %s => (%s)\n", resource_name, mod->info->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_set_flag(mod, FLAG_RUNNING);
|
mod->flags.running = 1;
|
||||||
|
|
||||||
ast_update_use_count();
|
ast_update_use_count();
|
||||||
break;
|
break;
|
||||||
case AST_MODULE_LOAD_DECLINE:
|
case AST_MODULE_LOAD_DECLINE:
|
||||||
ast_set_flag(mod, FLAG_DECLINED);
|
mod->flags.declined = 1;
|
||||||
break;
|
break;
|
||||||
case AST_MODULE_LOAD_FAILURE:
|
case AST_MODULE_LOAD_FAILURE:
|
||||||
break;
|
break;
|
||||||
|
@ -723,18 +721,15 @@ int load_modules(unsigned int preload_only)
|
||||||
if (option_verbose)
|
if (option_verbose)
|
||||||
ast_verbose("Asterisk Dynamic Loader Starting:\n");
|
ast_verbose("Asterisk Dynamic Loader Starting:\n");
|
||||||
|
|
||||||
AST_LIST_TRAVERSE(&module_list, mod, entry) {
|
AST_LIST_HEAD_INIT_NOLOCK(&load_order);
|
||||||
if (option_debug > 1)
|
|
||||||
ast_log(LOG_DEBUG, "Embedded module found: %s\n", mod->resource);
|
AST_LIST_LOCK(&module_list);
|
||||||
}
|
|
||||||
|
|
||||||
if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
|
if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
|
||||||
ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
|
ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
|
||||||
return 0;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_LIST_HEAD_INIT_NOLOCK(&load_order);
|
|
||||||
|
|
||||||
/* first, find all the modules we have been explicitly requested to load */
|
/* first, find all the modules we have been explicitly requested to load */
|
||||||
for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
|
for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
|
||||||
if (!strcasecmp(v->name, preload_only ? "preload" : "load"))
|
if (!strcasecmp(v->name, preload_only ? "preload" : "load"))
|
||||||
|
@ -743,9 +738,17 @@ int load_modules(unsigned int preload_only)
|
||||||
|
|
||||||
/* check if 'autoload' is on */
|
/* check if 'autoload' is on */
|
||||||
if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
|
if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
|
||||||
/* if so, first add all the embedded modules to the load order */
|
/* if so, first add all the embedded modules that are not already running to the load order */
|
||||||
AST_LIST_TRAVERSE(&module_list, mod, entry)
|
AST_LIST_TRAVERSE(&module_list, mod, entry) {
|
||||||
|
/* if it's not embedded, skip it */
|
||||||
|
if (mod->lib)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mod->flags.running)
|
||||||
|
continue;
|
||||||
|
|
||||||
order = add_to_load_order(mod->resource, &load_order);
|
order = add_to_load_order(mod->resource, &load_order);
|
||||||
|
}
|
||||||
|
|
||||||
#if LOADABLE_MODULES
|
#if LOADABLE_MODULES
|
||||||
/* if we are allowed to load dynamic modules, scan the directory for
|
/* if we are allowed to load dynamic modules, scan the directory for
|
||||||
|
@ -762,8 +765,12 @@ int load_modules(unsigned int preload_only)
|
||||||
if (strcasecmp(dirent->d_name + ld - 3, ".so"))
|
if (strcasecmp(dirent->d_name + ld - 3, ".so"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
add_to_load_order(dirent->d_name, &load_order);
|
/* if there is already a module by this name in the module_list,
|
||||||
|
skip this file */
|
||||||
|
if (find_resource(dirent->d_name, 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
add_to_load_order(dirent->d_name, &load_order);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
@ -846,6 +853,8 @@ done:
|
||||||
free(order);
|
free(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AST_LIST_UNLOCK(&module_list);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue