]> code.delx.au - pulseaudio/commitdiff
core-util: add api for setting env vars and record them so that we can undo them...
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2009 22:34:27 +0000 (00:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2009 22:34:27 +0000 (00:34 +0200)
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index 678230197860546eba10e0dc8f5a8c8e3f5a9d17..9034dc32bf2d57c166f87b271360ae7c0be4f509 100644 (file)
 #include <pulsecore/thread.h>
 #include <pulsecore/strbuf.h>
 #include <pulsecore/usergroup.h>
+#include <pulsecore/strlist.h>
 
 #include "core-util.h"
 
 #define MSG_NOSIGNAL 0
 #endif
 
+static pa_strlist *recorded_env = NULL;
+
 #ifdef OS_IS_WIN32
 
 #define PULSE_ROOTENV "PULSE_ROOT"
@@ -2451,9 +2454,36 @@ void pa_set_env(const char *key, const char *value) {
     pa_assert(key);
     pa_assert(value);
 
+    /* This is not thread-safe */
+
     putenv(pa_sprintf_malloc("%s=%s", key, value));
 }
 
+void pa_set_env_and_record(const char *key, const char *value) {
+    pa_assert(key);
+    pa_assert(value);
+
+    /* This is not thread-safe */
+
+    pa_set_env(key, value);
+    recorded_env = pa_strlist_prepend(recorded_env, key);
+}
+
+void pa_unset_env_recorded(void) {
+
+    /* This is not thread-safe */
+
+    for (;;) {
+        char *s = NULL;
+
+        if (!(recorded_env = pa_strlist_pop(recorded_env, &s)))
+            break;
+
+        unsetenv(s);
+        pa_xfree(s);
+    }
+}
+
 pa_bool_t pa_in_system_mode(void) {
     const char *e;
 
index 2551f7942d2c93de80852f1a8544f1c755455cb3..ccc9a38eee6dddfb3c8a1d8e59cdf7b345145f58 100644 (file)
@@ -195,6 +195,8 @@ int pa_reset_sigs(int except, ...);
 int pa_reset_sigsv(const int except[]);
 
 void pa_set_env(const char *key, const char *value);
+void pa_set_env_and_record(const char *key, const char *value);
+void pa_unset_env_recorded(void);
 
 pa_bool_t pa_in_system_mode(void);