mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
core-util: add api for setting env vars and record them so that we can undo them n fork
This commit is contained in:
parent
45513a2077
commit
5f929963d1
2 changed files with 32 additions and 0 deletions
|
|
@ -116,6 +116,7 @@
|
||||||
#include <pulsecore/thread.h>
|
#include <pulsecore/thread.h>
|
||||||
#include <pulsecore/strbuf.h>
|
#include <pulsecore/strbuf.h>
|
||||||
#include <pulsecore/usergroup.h>
|
#include <pulsecore/usergroup.h>
|
||||||
|
#include <pulsecore/strlist.h>
|
||||||
|
|
||||||
#include "core-util.h"
|
#include "core-util.h"
|
||||||
|
|
||||||
|
|
@ -124,6 +125,8 @@
|
||||||
#define MSG_NOSIGNAL 0
|
#define MSG_NOSIGNAL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static pa_strlist *recorded_env = NULL;
|
||||||
|
|
||||||
#ifdef OS_IS_WIN32
|
#ifdef OS_IS_WIN32
|
||||||
|
|
||||||
#define PULSE_ROOTENV "PULSE_ROOT"
|
#define PULSE_ROOTENV "PULSE_ROOT"
|
||||||
|
|
@ -2451,9 +2454,36 @@ void pa_set_env(const char *key, const char *value) {
|
||||||
pa_assert(key);
|
pa_assert(key);
|
||||||
pa_assert(value);
|
pa_assert(value);
|
||||||
|
|
||||||
|
/* This is not thread-safe */
|
||||||
|
|
||||||
putenv(pa_sprintf_malloc("%s=%s", key, value));
|
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) {
|
pa_bool_t pa_in_system_mode(void) {
|
||||||
const char *e;
|
const char *e;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,8 @@ int pa_reset_sigs(int except, ...);
|
||||||
int pa_reset_sigsv(const int except[]);
|
int pa_reset_sigsv(const int except[]);
|
||||||
|
|
||||||
void pa_set_env(const char *key, const char *value);
|
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);
|
pa_bool_t pa_in_system_mode(void);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue