From: Sven Trenkel Date: Thu, 29 Oct 2009 12:24:39 +0000 (+0100) Subject: Better workaround for global plugin loading. X-Git-Tag: collectd-4.9.0~35^2~29 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=a1a8bdce8ff1d7c70f3fbf94e8ffe4c3aac8715c Better workaround for global plugin loading. --- diff --git a/src/configfile.c b/src/configfile.c index 1a957f67..79ad9f6d 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -75,7 +75,7 @@ typedef struct cf_global_option_s */ static int dispatch_value_typesdb (const oconfig_item_t *ci); static int dispatch_value_plugindir (const oconfig_item_t *ci); -static int dispatch_value_loadplugin (const oconfig_item_t *ci); +static int dispatch_loadplugin (const oconfig_item_t *ci); /* * Private variables @@ -87,7 +87,7 @@ static cf_value_map_t cf_value_map[] = { {"TypesDB", dispatch_value_typesdb}, {"PluginDir", dispatch_value_plugindir}, - {"LoadPlugin", dispatch_value_loadplugin} + {"LoadPlugin", dispatch_loadplugin} }; static int cf_value_map_num = STATIC_ARRAY_LEN (cf_value_map); @@ -239,8 +239,10 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) return (0); } -static int dispatch_value_loadplugin (const oconfig_item_t *ci) +static int dispatch_loadplugin (const oconfig_item_t *ci) { + int i; + uint32_t flags = 0; assert (strcasecmp (ci->key, "LoadPlugin") == 0); if (ci->values_num != 1) @@ -248,7 +250,19 @@ static int dispatch_value_loadplugin (const oconfig_item_t *ci) if (ci->values[0].type != OCONFIG_TYPE_STRING) return (-1); - return (plugin_load (ci->values[0].value.string)); + for (i = 0; i < ci->children_num; ++i) { + if (ci->children[i].values_num != 1 || + ci->children[i].values[0].type != OCONFIG_TYPE_BOOLEAN) { + WARNING("Ignoring unknown LoadPlugin option %s for plugin %s", ci->children[i].key, ci->values[0].value.string); + continue; + } + if (strcasecmp(ci->children[i].key, "globals") == 0) { + flags |= PLUGIN_FLAGS_GLOBAL; + } else { + WARNING("Ignoring unknown LoadPlugin option %s for plugin %s", ci->children[i].key, ci->values[0].value.string); + } + } + return (plugin_load (ci->values[0].value.string, flags)); } /* int dispatch_value_loadplugin */ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) @@ -353,7 +367,9 @@ static int dispatch_block_plugin (oconfig_item_t *ci) static int dispatch_block (oconfig_item_t *ci) { - if (strcasecmp (ci->key, "Plugin") == 0) + if (strcasecmp (ci->key, "LoadPlugin") == 0) + return (dispatch_loadplugin (ci)); + else if (strcasecmp (ci->key, "Plugin") == 0) return (dispatch_block_plugin (ci)); else if (strcasecmp (ci->key, "Threshold") == 0) return (ut_config (ci)); diff --git a/src/plugin.c b/src/plugin.c index 97885a3b..7b30e211 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -270,7 +270,7 @@ 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) +static int plugin_load_file (char *file, uint32_t flags) { lt_dlhandle dlh; void (*reg_handle) (void); @@ -280,8 +280,7 @@ static int plugin_load_file (char *file) lt_dlinit (); lt_dlerror (); /* clear errors */ - /* XXX BUG FIXME */ - if (strstr(file, "python") != NULL) { + if (flags & PLUGIN_FLAGS_GLOBAL) { lt_dladvise advise; lt_dladvise_init(&advise); lt_dladvise_global(&advise); @@ -545,7 +544,7 @@ void plugin_set_dir (const char *dir) } #define BUFSIZE 512 -int plugin_load (const char *type) +int plugin_load (const char *type, uint32_t flags) { DIR *dh; const char *dir; @@ -607,7 +606,7 @@ int plugin_load (const char *type) continue; } - if (plugin_load_file (filename) == 0) + if (plugin_load_file (filename, flags) == 0) { /* success */ ret = 0; diff --git a/src/plugin.h b/src/plugin.h index b35fcf18..e576141f 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -26,6 +26,8 @@ #include "configfile.h" #include "meta_data.h" +#define PLUGIN_FLAGS_GLOBAL 0x0001 + #define DATA_MAX_NAME_LEN 64 #define DS_TYPE_COUNTER 0 @@ -200,7 +202,7 @@ void plugin_set_dir (const char *dir); * * ARGUMENTS * `name' Name of the plugin to load. - * `mr' Types of functions to request from the plugin. + * `flags' Hints on how to handle this plugin. * * RETURN VALUE * Returns zero upon success, a value greater than zero if no plugin was found @@ -209,7 +211,7 @@ void plugin_set_dir (const char *dir); * NOTES * No attempt is made to re-load an already loaded module. */ -int plugin_load (const char *name); +int plugin_load (const char *name, uint32_t flags); void plugin_init_all (void); void plugin_read_all (void); diff --git a/src/pyvalues.c b/src/pyvalues.c index 21590743..9a0c87f3 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -209,13 +209,13 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { * Not much we can do about it */ num = PyNumber_Long(item); if (num != NULL) - value[i].gauge = PyLong_AsLongLong(num); + value[i].derive = PyLong_AsLongLong(num); } else if (ds->ds->type == DS_TYPE_ABSOLUTE) { /* This might overflow without raising an exception. * Not much we can do about it */ num = PyNumber_Long(item); if (num != NULL) - value[i].gauge = PyLong_AsUnsignedLongLong(num); + value[i].absolute = PyLong_AsUnsignedLongLong(num); } else { free(value); PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, type);