From e28829b44af3250063e728bdcfc3fcdc86e3ab83 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Oct 2008 18:12:50 +0200 Subject: [PATCH] obexd: Use dlopen() directly and don't depend on GModule --- obexd/src/plugin.c | 60 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/obexd/src/plugin.c b/obexd/src/plugin.c index d0dc5b16a..37b2df094 100644 --- a/obexd/src/plugin.c +++ b/obexd/src/plugin.c @@ -25,38 +25,39 @@ #include #endif -#include -#include +#include +#include #include - #include -#include -#include "logging.h" +#include #include "plugin.h" +#include "logging.h" static GSList *plugins = NULL; struct obex_plugin { - GModule *module; + void *handle; struct obex_plugin_desc *desc; }; -static gboolean add_plugin(GModule *module, struct obex_plugin_desc *desc) +static gboolean add_plugin(void *handle, struct obex_plugin_desc *desc) { struct obex_plugin *plugin; - if (desc->init() < 0) - return FALSE; - plugin = g_try_new0(struct obex_plugin, 1); if (plugin == NULL) return FALSE; - plugin->module = module; + plugin->handle = handle; plugin->desc = desc; + if (desc->init() < 0) { + g_free(plugin); + return FALSE; + } + plugins = g_slist_append(plugins, plugin); return TRUE; @@ -77,8 +78,8 @@ gboolean plugin_init(void) return FALSE; while ((file = g_dir_read_name(dir)) != NULL) { - GModule *module; struct obex_plugin_desc *desc; + void *handle; gchar *filename; struct stat st; @@ -89,39 +90,36 @@ gboolean plugin_init(void) filename = g_build_filename(PLUGINDIR, file, NULL); if (stat(filename, &st) < 0) { - error("Can't load plugin %s: %s (%d)", filename, - strerror(errno), errno); + error("Can't find plugin %s: %s", filename, + strerror(errno)); g_free(filename); continue; } - module = g_module_open(filename, G_MODULE_BIND_LOCAL); - if (module == NULL) { - error("Can't load plugin: %s", g_module_error()); + handle = dlopen(filename, RTLD_NOW); + if (handle == NULL) { + error("Can't load plugin %s: %s", filename, + dlerror()); g_free(filename); continue; } g_free(filename); - debug("%s", g_module_name(module)); - - if (g_module_symbol(module, "obex_plugin_desc", - (gpointer) &desc) == FALSE) { - error("Can't load plugin description"); - g_module_close(module); + desc = dlsym(handle, "obex_plugin_desc"); + if (desc == NULL) { + error("Can't load plugin description: %s", dlerror()); + dlclose(handle); continue; } - if (desc == NULL || desc->init == NULL) { - g_module_close(module); + if (desc->init == NULL) { + dlclose(handle); continue; } - if (add_plugin(module, desc) == FALSE) { - error("Can't init plugin %s", g_module_name(module)); - g_module_close(module); - } + if (add_plugin(handle, desc) == FALSE) + dlclose(handle); } g_dir_close(dir); @@ -138,12 +136,10 @@ void plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct obex_plugin *plugin = list->data; - debug("%s", g_module_name(plugin->module)); - if (plugin->desc->exit) plugin->desc->exit(); - g_module_close(plugin->module); + dlclose(plugin->handle); g_free(plugin); } -- 2.47.3