aboutsummaryrefslogtreecommitdiffstats
path: root/loader.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-04-06 09:10:31 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-04-06 09:10:31 +0000
commite74b126e91e7bf13630d1ca21f99237f7a346716 (patch)
treed05b6273543906f19e3cf3e069189c4888bb42e8 /loader.c
parent4decf040938286b0efc6802a44b22304981ef9f9 (diff)
small cleanups to module.h and loader.c to start playing with
new-style modules using static symbols. Everything will still work as before, but new-style modules can now be defined by putting a '#define STATIC_MODULE' somewhere before including module.h, then declaring STATIC_MODULE the various methods (load, unload, key...) that the module is supposed to supply, and adding a 'STD_MOD(MOD_1, reload_fn, NULL, NULL)' macro call at the end. A module compiled in this way will be loaded RTLD_NOW|RTLD_LOCAL so symbol pollution is reduced, and symbols are resolved immediately. Removing just the '#define STATIC_MODULE' will restore the old behaviour. In order for a module to be loaded RTLD_NOW|RTLD_LOCAL, it must not export any symbol[1], and all the modules it depends on (e.g. res_*) must be loaded already. [1] Mechanisms are in place, and will be enabled later, to still allow such modules to 'export' symbols and resolving the dependencies irrespective of the load order. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@17790 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'loader.c')
-rw-r--r--loader.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/loader.c b/loader.c
index d467528a5..08dca973a 100644
--- a/loader.c
+++ b/loader.c
@@ -683,26 +683,20 @@ static struct module * __load_resource(const char *resource_name,
int res;
struct module *cur;
struct module_symbols *m, *m1;
- int flags=RTLD_NOW;
+ int flags = RTLD_NOW;
unsigned char *key;
char tmp[80];
- if (strncasecmp(resource_name, "res_", 4)) {
-#ifdef RTLD_GLOBAL
- if (cfg) {
- char *val;
- if ((val = ast_variable_retrieve(cfg, "global", resource_name))
- && ast_true(val))
- flags |= RTLD_GLOBAL;
- }
+#ifndef RTLD_GLOBAL
+#define RTLD_GLOBAL 0 /* so it is a No-op */
#endif
+ if (strncasecmp(resource_name, "res_", 4) && cfg) {
+ char *val = ast_variable_retrieve(cfg, "global", resource_name);
+ if (val && ast_true(val))
+ flags |= RTLD_GLOBAL;
} else {
/* Resource modules are always loaded global and lazy */
-#ifdef RTLD_GLOBAL
flags = (RTLD_GLOBAL | RTLD_LAZY);
-#else
- flags = RTLD_LAZY;
-#endif
}
if (AST_LIST_LOCK(&module_list))
@@ -722,16 +716,19 @@ static struct module * __load_resource(const char *resource_name,
ast_copy_string(fn, resource_name, sizeof(fn));
else
snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_MODULE_DIR, resource_name);
-#if 0
- /* XXX test, open in a sane way */
+
+ /* open in a sane way */
cur->lib = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (cur->lib == NULL) {
- ast_log(LOG_WARNING, "test %s\n", dlerror());
- } else
+ ast_log(LOG_WARNING, "cannot load %s %s\n", fn, dlerror());
+ } else if ( (m1 = find_symbol(cur, "mod_data", 0)) == NULL || m1->type == MOD_0) {
+ /* old-style module, close and reload with standard flags */
dlclose(cur->lib);
-#endif
+ cur->lib = NULL;
+ }
+ if (cur->lib == NULL) /* try reopen with the old style */
+ cur->lib = dlopen(fn, flags);
- cur->lib = dlopen(fn, flags);
if (!cur->lib) {
ast_log(LOG_WARNING, "%s\n", dlerror());
free(cur);
@@ -740,10 +737,10 @@ static struct module * __load_resource(const char *resource_name,
}
m1 = find_symbol(cur, "mod_data", 0);
if (m1 != NULL) { /* new style module */
+ ast_log(LOG_WARNING, "new style %s (%d) loaded RTLD_LOCAL\n",
+ resource_name, m1->type);
errors = check_exported(cur);
*m = *m1;
- if (m->type == MOD_2)
- ast_log(LOG_WARNING, "new style %s, should unload and reload with RTLD_LOCAL\n", resource_name);
} else {
m->type = MOD_0;
m->load_module = find_symbol(cur, "load_module", 1);