[collectd] [PATCH] configfile: Use putenv() if setenv() is not available.
Sebastian Harl
sh at tokkee.org
Tue May 20 11:06:54 CEST 2008
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
configure.in | 2 +-
src/configfile.c | 18 +++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/configure.in b/configure.in
index ce56227..24989c4 100644
--- a/configure.in
+++ b/configure.in
@@ -369,7 +369,7 @@ AC_HEADER_TIME
# Checks for library functions.
#
AC_PROG_GCC_TRADITIONAL
-AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog)
+AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog setenv putenv)
AC_FUNC_STRERROR_R
diff --git a/src/configfile.c b/src/configfile.c
index cf67196..bd9cdfc 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -203,6 +203,8 @@ static int dispatch_value_env (const oconfig_item_t *ci)
char *name = NULL;
char *value = NULL;
+ int status = 0;
+
assert (strcasecmp (ci->key, "env") == 0);
if ((ci->values_num != 2)
@@ -215,7 +217,21 @@ static int dispatch_value_env (const oconfig_item_t *ci)
name = ci->values[0].value.string;
value = ci->values[1].value.string;
- if (setenv (name, value, 1 /* overwrite */) != 0)
+#if HAVE_SETENV
+ status = setenv (name, value, 1 /* overwrite */);
+#elif HAVE_PUTENV
+ {
+ char buf[1024];
+
+ ssnprintf (buf, sizeof (buf), "%s=%s", name, value);
+ /* the string passed to putenv becomes part of the environment */
+ status = putenv (sstrdup (buf));
+ }
+#else
+# error "Neither setenv nor putenv seem to be available."
+#endif
+
+ if (status != 0)
{
char errbuf[1024];
ERROR ("configfile: Failed to set environment variable `%s': %s",
--
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/c9038981/attachment.pgp
More information about the collectd
mailing list