X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=b37e9b325c32e9492e92a3e29caa49a5e78d34e4;hb=c3d354c58d56c4b2bb4138a227f3546928bd84f2;hp=f313f3680be60fe442f7596194cbf9b96769953f;hpb=3fb6fe5776c14f41879249f4147c0b8924b39cc1;p=collectd.git diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index f313f368..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 @@ -153,14 +153,13 @@ static const char *plugin_get_dir(void) { return (plugindir); } -static void plugin_update_internal_statistics(void) { /* {{{ */ - +static int plugin_update_internal_statistics(void) { /* {{{ */ gauge_t copy_write_queue_length = (gauge_t)write_queue_length; /* Initialize `vl' */ value_list_t vl = VALUE_LIST_INIT; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "collectd", sizeof(vl.plugin)); + vl.interval = plugin_get_interval(); /* Write queue */ sstrncpy(vl.plugin_instance, "write_queue", sizeof(vl.plugin_instance)); @@ -189,8 +188,8 @@ static void plugin_update_internal_statistics(void) { /* {{{ */ vl.type_instance[0] = 0; plugin_dispatch_values(&vl); - return; -} /* }}} void plugin_update_internal_statistics */ + return 0; +} /* }}} int plugin_update_internal_statistics */ static void destroy_callback(callback_func_t *cf) /* {{{ */ { @@ -389,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 @@ -433,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); } @@ -973,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] = ""; @@ -1007,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 */ @@ -1045,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); @@ -1572,8 +1557,10 @@ int plugin_init_all(void) { /* Init the value cache */ uc_init(); - if (IS_TRUE(global_option_get("CollectInternalStats"))) + if (IS_TRUE(global_option_get("CollectInternalStats"))) { record_statistics = 1; + plugin_register_read("collectd", plugin_update_internal_statistics); + } chain_name = global_option_get("PreCacheChain"); pre_cache_chain = fc_chain_get_by_name(chain_name); @@ -1661,9 +1648,6 @@ int plugin_init_all(void) { /* TODO: Rename this function. */ void plugin_read_all(void) { - if (record_statistics) { - plugin_update_internal_statistics(); - } uc_check_timeout(); return; @@ -2592,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 : */