X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=b37e9b325c32e9492e92a3e29caa49a5e78d34e4;hb=3e0dd5070e385b864c771902bfa4c6331c5710b4;hp=0f067374d05e7148ce79ae32a44d531e5db42ac2;hpb=ffaf9b893b6042a76e1c0dadd83ce06904fcc89a;p=collectd.git diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 0f067374..b37e9b32 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -46,7 +46,7 @@ #include /* for pthread_set_name_np(3) */ #endif -#include +#include /* * Private structures @@ -388,40 +388,25 @@ static int plugin_unregister(llist_t *list, const char *name) /* {{{ */ * object, but it will bitch about a shared object not having a * ``module_register'' symbol.. */ -static int plugin_load_file(char *file, uint32_t flags) { - lt_dlhandle dlh; +static int plugin_load_file(const char *file, _Bool global) { void (*reg_handle)(void); - lt_dlinit(); - lt_dlerror(); /* clear errors */ + int flags = RTLD_NOW; + if (global) + flags |= RTLD_GLOBAL; -#if LIBTOOL_VERSION == 2 - if (flags & PLUGIN_FLAGS_GLOBAL) { - lt_dladvise advise; - lt_dladvise_init(&advise); - lt_dladvise_global(&advise); - dlh = lt_dlopenadvise(file, advise); - lt_dladvise_destroy(&advise); - } else { - dlh = lt_dlopen(file); - } -#else /* if LIBTOOL_VERSION == 1 */ - if (flags & PLUGIN_FLAGS_GLOBAL) - WARNING("plugin_load_file: The global flag is not supported, " - "libtool 2 is required for this."); - dlh = lt_dlopen(file); -#endif + void *dlh = dlopen(file, flags); if (dlh == NULL) { char errbuf[1024] = ""; ssnprintf(errbuf, sizeof(errbuf), - "lt_dlopen (\"%s\") failed: %s. " + "dlopen (\"%s\") failed: %s. " "The most common cause for this problem is " "missing dependencies. Use ldd(1) to check " "the dependencies of the plugin " "/ shared object.", - file, lt_dlerror()); + file, dlerror()); ERROR("%s", errbuf); /* Make sure this is printed to STDERR in any case, but also @@ -432,10 +417,11 @@ static int plugin_load_file(char *file, uint32_t flags) { return (1); } - if ((reg_handle = (void (*)(void))lt_dlsym(dlh, "module_register")) == NULL) { + reg_handle = (void (*)(void))dlsym(dlh, "module_register"); + if (reg_handle == NULL) { WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file, - lt_dlerror()); - lt_dlclose(dlh); + dlerror()); + dlclose(dlh); return (-1); } @@ -972,7 +958,7 @@ static void plugin_free_loaded(void) { } #define BUFSIZE 512 -int plugin_load(char const *plugin_name, uint32_t flags) { +int plugin_load(char const *plugin_name, _Bool global) { DIR *dh; const char *dir; char filename[BUFSIZE] = ""; @@ -1006,7 +992,7 @@ int plugin_load(char const *plugin_name, uint32_t flags) { */ if ((strcasecmp("perl", plugin_name) == 0) || (strcasecmp("python", plugin_name) == 0)) - flags |= PLUGIN_FLAGS_GLOBAL; + global = 1; /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the * type when matching the filename */ @@ -1044,7 +1030,7 @@ int plugin_load(char const *plugin_name, uint32_t flags) { continue; } - status = plugin_load_file(filename, flags); + status = plugin_load_file(filename, global); if (status == 0) { /* success */ plugin_mark_loaded(plugin_name); @@ -2590,5 +2576,3 @@ int plugin_thread_create(pthread_t *thread, const pthread_attr_t *attr, return 0; } /* int plugin_thread_create */ - -/* vim: set sw=8 ts=8 noet fdm=marker : */