From d26335bfea97b4bd49f6f964b8bd7239386e2b88 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 19 Dec 2010 14:16:59 +0100 Subject: [PATCH] src/configfile.c: Enable the "Globals" flag for the Perl and Python plugin. This special handling hopefully saves the average user from ever getting in contact with the "Globals" option. --- src/collectd.conf.pod | 18 +++++++++++------- src/configfile.c | 38 +++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 7579664b..589e1694 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -72,15 +72,19 @@ options are allowed inside a B block: If enabled, collectd will export all global symbols of the plugin (and of all libraries loaded as dependencies of the plugin) and, thus, makes those symbols available for resolving unresolved symbols in subsequently loaded plugins if -that is supported by your system. By default, this is disabled. +that is supported by your system. -This is useful (or possibly even required), e.Eg., when loading a plugin -that embeds some scripting language into the daemon (e.Eg. the C -or C plugins). Scripting languages usually provide means to load +This is useful (or possibly even required), e.g., when loading a plugin that +embeds some scripting language into the daemon (e.g. the I and +I). Scripting languages usually provide means to load extensions written in C. Those extensions require symbols provided by the -interpreter, which is loaded as a dependency of the respective collectd -plugin. See the documentation of those plugins (e.Eg., -L or L) for details. +interpreter, which is loaded as a dependency of the respective collectd plugin. +See the documentation of those plugins (e.g., L or +L) for details. + +By default, this is disabled. As a special exception, if the plugin name is +either C or C, the default is changed to enabled in order to keep +the average user from ever having to deal with this low level linking stuff. =back diff --git a/src/configfile.c b/src/configfile.c index 11200f61..33a7c200 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -242,7 +242,8 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) static int dispatch_loadplugin (const oconfig_item_t *ci) { int i; - uint32_t flags = 0; + const char *name; + unsigned int flags = 0; assert (strcasecmp (ci->key, "LoadPlugin") == 0); if (ci->values_num != 1) @@ -250,19 +251,34 @@ static int dispatch_loadplugin (const oconfig_item_t *ci) if (ci->values[0].type != OCONFIG_TYPE_STRING) return (-1); + name = ci->values[0].value.string; + + /* + * XXX: Magic at work: + * + * Some of the language bindings, for example the Python and Perl + * plugins, need to be able to export symbols to the scripts they run. + * For this to happen, the "Globals" flag needs to be set. + * Unfortunately, this technical detail is hard to explain to the + * average user and she shouldn't have to worry about this, ideally. + * So in order to save everyone's sanity use a different default for a + * handful of special plugins. --octo + */ + if ((strcasecmp ("Perl", name) == 0) + || (strcasecmp ("Python", name) == 0)) + flags |= PLUGIN_FLAGS_GLOBAL; + 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); + if (strcasecmp("Globals", ci->children[i].key) == 0) + cf_util_get_flag (ci->children + i, &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)); + + return (plugin_load (name, (uint32_t) flags)); } /* int dispatch_value_loadplugin */ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) -- 2.11.0