From 53df62e6f94e30bc8f099af7c858d38a94fddf4b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Oct 2008 19:03:30 +0200 Subject: Use dlopen() directly and don't depend on GModule --- acinclude.m4 | 8 -------- configure.ac | 4 +++- src/Makefile.am | 9 +++++---- src/plugin.c | 62 +++++++++++++++++++++++++-------------------------------- 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 45dd9096..c779a843 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -115,14 +115,6 @@ AC_DEFUN([AC_PATH_GLIB], [ AC_SUBST(GLIB_LIBS) ]) -AC_DEFUN([AC_PATH_GMODULE], [ - PKG_CHECK_MODULES(GMODULE, gmodule-2.0, dummy=yes, - AC_MSG_ERROR(GModule library is required)) - AC_CHECK_LIB(dl, dlopen, dummy=yes, dummy=no) - AC_SUBST(GMODULE_CFLAGS) - AC_SUBST(GMODULE_LIBS) -]) - AC_DEFUN([AC_PATH_GSTREAMER], [ PKG_CHECK_MODULES(GSTREAMER, gstreamer-0.10 gstreamer-plugins-base-0.10, gstreamer_found=yes, gstreamer_found=no) AC_SUBST(GSTREAMER_CFLAGS) diff --git a/configure.ac b/configure.ac index 8fa7282b..31000a2b 100644 --- a/configure.ac +++ b/configure.ac @@ -26,9 +26,11 @@ GTK_DOC_CHECK AC_FUNC_PPOLL +AC_CHECK_LIB(dl, dlopen, dummy=yes, + AC_MSG_ERROR(dynamic linking loader is required)) + AC_PATH_DBUS AC_PATH_GLIB -AC_PATH_GMODULE AC_PATH_ALSA AC_PATH_GSTREAMER AC_PATH_USB diff --git a/src/Makefile.am b/src/Makefile.am index 2a353a47..af525773 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,9 @@ bluetoothd_SOURCES = main.c security.c hcid.h sdpd.h \ device.h device.c dbus-common.c dbus-common.h dbus-hci.h dbus-hci.c bluetoothd_LDADD = $(top_builddir)/common/libhelper.a \ - @GDBUS_LIBS@ @GMODULE_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ + @GDBUS_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ -ldl + +bluetoothd_LDFLAGS = -Wl,--export-dynamic if MAINTAINER_MODE plugindir = $(abs_top_srcdir)/plugins @@ -30,9 +32,8 @@ else plugindir = $(libdir)/bluetooth/plugins endif -AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ \ - @GLIB_CFLAGS@ @GMODULE_CFLAGS@ @GDBUS_CFLAGS@ \ - -DPLUGINDIR=\""$(plugindir)"\" +AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ \ + -DPLUGINDIR=\""$(plugindir)"\" INCLUDES = -I$(top_srcdir)/common diff --git a/src/plugin.c b/src/plugin.c index 380d482c..ca4de256 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -25,40 +25,42 @@ #include #endif -#include -#include +#include +#include #include - #include -#include - -#include -#include "logging.h" +#include #include "plugin.h" +#include "logging.h" static GSList *plugins = NULL; struct bluetooth_plugin { - GModule *module; + void *handle; struct bluetooth_plugin_desc *desc; }; -static gboolean add_plugin(GModule *module, struct bluetooth_plugin_desc *desc) +static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc) { struct bluetooth_plugin *plugin; - if (desc->init() < 0) + if (desc->init == NULL) return FALSE; plugin = g_try_new0(struct bluetooth_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; @@ -110,8 +112,8 @@ gboolean plugin_init(GKeyFile *config) } while ((file = g_dir_read_name(dir)) != NULL) { - GModule *module; struct bluetooth_plugin_desc *desc; + void *handle; gchar *filename; struct stat st; @@ -125,39 +127,31 @@ gboolean plugin_init(GKeyFile *config) 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, "bluetooth_plugin_desc", - (gpointer) &desc) == FALSE) { - error("Can't load plugin description"); - g_module_close(module); + desc = dlsym(handle, "bluetooth_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); - 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); @@ -176,12 +170,10 @@ void plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct bluetooth_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); } -- cgit