[collectd] [PATCH] configfile: Added the "env" configuration option.
Sebastian Harl
sh at tokkee.org
Tue May 20 11:04:25 CEST 2008
This option adds or modifies environment variables. This might be useful
e.g. when using the "dektop_notification" plugin to set DISPLAY and
XAUTHORITY so that collectd can access the X server.
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
src/collectd.conf.in | 2 ++
src/collectd.conf.pod | 4 ++++
src/configfile.c | 29 +++++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index eaa3de1..d5cb81a 100644
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
@@ -4,6 +4,8 @@
# http://collectd.org/
#
+#env "DISPLAY" "localhost:0.0"
+
#Hostname "localhost"
FQDNLookup true
#BaseDir "@prefix@/var/lib/@PACKAGE_NAME@"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 2c4ff46..5e9db9e 100644
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -42,6 +42,10 @@ B<before> the C<E<lt>Plugin ...E<gt>> block.
=over 4
+=item B<env> I<name> I<value>
+
+Add or modify the environment variable I<name>. The value is set to I<value>.
+
=item B<BaseDir> I<Directory>
Sets the base directory. This is the directory beneath all RRD-files are
diff --git a/src/configfile.c b/src/configfile.c
index 2afef4f..cf67196 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -72,6 +72,7 @@ typedef struct cf_global_option_s
/*
* Prototypes of callback functions
*/
+static int dispatch_value_env (const oconfig_item_t *ci);
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);
@@ -84,6 +85,7 @@ static cf_complex_callback_t *complex_callback_head = NULL;
static cf_value_map_t cf_value_map[] =
{
+ {"env", dispatch_value_env},
{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
{"LoadPlugin", dispatch_value_loadplugin}
@@ -196,6 +198,33 @@ static int dispatch_global_option (const oconfig_item_t *ci)
return (-1);
} /* int dispatch_global_option */
+static int dispatch_value_env (const oconfig_item_t *ci)
+{
+ char *name = NULL;
+ char *value = NULL;
+
+ assert (strcasecmp (ci->key, "env") == 0);
+
+ if ((ci->values_num != 2)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)
+ || (ci->values[1].type != OCONFIG_TYPE_STRING)) {
+ ERROR ("configfile: `env' needs exactly two string arguments.");
+ return (-1);
+ }
+
+ name = ci->values[0].value.string;
+ value = ci->values[1].value.string;
+
+ if (setenv (name, value, 1 /* overwrite */) != 0)
+ {
+ char errbuf[1024];
+ ERROR ("configfile: Failed to set environment variable `%s': %s",
+ name, sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+ return (0);
+} /* int dispatch_value_env */
+
static int dispatch_value_typesdb (const oconfig_item_t *ci)
{
int i = 0;
--
1.5.5.1.316.g377d9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080520/8c2fc11e/attachment.pgp
More information about the collectd
mailing list