Add new _dbus_get_environment call
authorRay Strode <rstrode@redhat.com>
Thu, 10 Jul 2008 16:45:36 +0000 (12:45 -0400)
committerRay Strode <rstrode@redhat.com>
Sat, 12 Jul 2008 03:58:53 +0000 (23:58 -0400)
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.

dbus/dbus-sysdeps.c
dbus/dbus-sysdeps.h

index 1a736e4..d740f87 100644 (file)
@@ -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.
  *
index 5ff1388..80236f0 100644 (file)
@@ -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;