summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2008-07-10 12:45:36 -0400
committerRay Strode <rstrode@redhat.com>2008-07-11 23:58:53 -0400
commit417c41f6c1ca122e1ce72a920bfc8c3ee841bf3c (patch)
tree7692ed07a2cae94fb8443a0f8b52a67c453ca5e9
parent458c6ead8572f8cea248844b6860156a00f3f45b (diff)
Add new _dbus_get_environment call
It's a wrapper around the environ external variable. It will be important in the future when we allow bus clients to modify the environment of future activated clients. Presently, we just always use the bus daemon environment wholesale.
-rw-r--r--dbus/dbus-sysdeps.c42
-rw-r--r--dbus/dbus-sysdeps.h1
2 files changed, 43 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index 1a736e42..d740f875 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -200,6 +200,48 @@ _dbus_clearenv (void)
return rc;
}
+/**
+ * Gets a #NULL-terminated list of key=value pairs from the
+ * environment. Use dbus_free_string_array to free it.
+ *
+ * @returns the environment or #NULL on OOM
+ */
+char **
+_dbus_get_environment (void)
+{
+ int i, length;
+ extern char **environ;
+ char **environment;
+
+ _dbus_assert (environ != NULL);
+
+ for (length = 0; environ[length] != NULL; length++);
+
+ /* Add one for NULL */
+ length++;
+
+ environment = dbus_new0 (char *, length);
+
+ if (environment == NULL)
+ return NULL;
+
+ for (i = 0; environ[i] != NULL; i++)
+ {
+ environment[i] = _dbus_strdup (environ[i]);
+
+ if (environment[i] == NULL)
+ break;
+ }
+
+ if (environ[i] != NULL)
+ {
+ dbus_free_string_array (environment);
+ environment = NULL;
+ }
+
+ return environment;
+}
+
/*
* init a pipe instance.
*
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 5ff13884..80236f05 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -101,6 +101,7 @@ const char* _dbus_getenv (const char *varname);
dbus_bool_t _dbus_setenv (const char *varname,
const char *value);
dbus_bool_t _dbus_clearenv (void);
+char ** _dbus_get_environment (void);
/** A process ID */
typedef unsigned long dbus_pid_t;