From 3f1c2f62110b08abb7299aa4a8a32cc55e071670 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 30 Sep 2012 21:37:58 +0200 Subject: [PATCH] Plugin loader and registration fixes - Use RTLD_GLOBAL flag to tell dynamic loader to load dependent .so files as well. Also lets other plugins use globally scoped symbols. - Check for plugin hooks as well before dismissing plugin as unused. Signed-off-by: Joachim Nilsson --- plugin.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugin.c b/plugin.c index fd497d1d..2e6067a4 100644 --- a/plugin.c +++ b/plugin.c @@ -41,7 +41,7 @@ static LIST_HEAD(, plugin) plugins = LIST_HEAD_INITIALIZER(); int plugin_register(plugin_t *plugin) { - int inuse = 0; + int i, inuse = 0; if (!plugin) { errno = EINVAL; @@ -78,8 +78,13 @@ int plugin_register(plugin_t *plugin) } } + for (i = 0; i < HOOK_MAX_NUM; i++) { + if (plugin->hook[i].cb) + inuse++; + } + if (!inuse) { - _e("No service \"%s\" loaded, skipping plugin.", basename(plugin->name)); + _e("No service \"%s\" loaded, and no I/O or finit hooks, skipping plugin.", basename(plugin->name)); return 1; } @@ -190,13 +195,13 @@ int plugin_load_all(char *path) if (!strcmp(ext, ".so")) { void *handle; - char filename[1024]; + char plugin[1024]; - snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name); - print_desc(" Loading plugin ", basename(filename)); - handle = dlopen(filename, RTLD_LAZY); + snprintf(plugin, sizeof(plugin), "%s/%s", path, entry->d_name); + print_desc(" Loading plugin ", basename(plugin)); + handle = dlopen(plugin, RTLD_LAZY | RTLD_GLOBAL); if (!handle) { - _d("Failed loading plugin %s: %s", filename, dlerror()); + _d("Failed loading plugin %s: %s", plugin, dlerror()); print_result(1); return 1; }