From 5f929963d12c70193a923d620177125d8608f18a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Sep 2009 00:34:27 +0200 Subject: core-util: add api for setting env vars and record them so that we can undo them n fork --- src/pulsecore/core-util.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 67823019..9034dc32 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -116,6 +116,7 @@ #include #include #include +#include #include "core-util.h" @@ -124,6 +125,8 @@ #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; -- cgit From 767c7c7cf42463c591edaa5e5cdc7930fa0f6026 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Sep 2009 04:03:18 +0200 Subject: core-util: call dbus_connection_set_exit_on_disconnect() on shared busses to make sure dbus_shutdown() isn't fatal --- src/pulsecore/core-util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 9034dc32..eeb81a60 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -612,6 +612,11 @@ static int set_scheduler(int rtprio) { return -1; } + /* We need to disable exit on disconnect because otherwise + * dbus_shutdown will kill us. See + * https://bugs.freedesktop.org/show_bug.cgi?id=16924 */ + dbus_connection_set_exit_on_disconnect(bus, FALSE); + r = rtkit_make_realtime(bus, 0, rtprio); dbus_connection_unref(bus); @@ -680,6 +685,11 @@ static int set_nice(int nice_level) { return -1; } + /* We need to disable exit on disconnect because otherwise + * dbus_shutdown will kill us. See + * https://bugs.freedesktop.org/show_bug.cgi?id=16924 */ + dbus_connection_set_exit_on_disconnect(bus, FALSE); + r = rtkit_make_high_priority(bus, 0, nice_level); dbus_connection_unref(bus); -- cgit From 297afadbef238f7a37f65bd3740a2ce24861c414 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Sep 2009 04:05:34 +0200 Subject: core-util: don't leak memory in pa_unset_env_recorded() --- src/pulsecore/core-util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 9034dc32..a3c60130 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2474,9 +2474,11 @@ void pa_unset_env_recorded(void) { /* This is not thread-safe */ for (;;) { - char *s = NULL; + char *s; - if (!(recorded_env = pa_strlist_pop(recorded_env, &s))) + recorded_env = pa_strlist_pop(recorded_env, &s); + + if (!s) break; unsetenv(s); -- cgit From f5046759cdd72daf5ba3b31c9dfc7b8d5be6bc9b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Sep 2009 23:46:23 +0200 Subject: llvm-clang-analyzer: drop a few unnecessary assignments and other trivial fixes --- src/pulsecore/core-util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 1daa46eb..d64c7388 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -591,13 +591,13 @@ static int set_scheduler(int rtprio) { sp.sched_priority = rtprio; #ifdef SCHED_RESET_ON_FORK - if ((r = pthread_setschedparam(pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp)) == 0) { + if (pthread_setschedparam(pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp) == 0) { pa_log_debug("SCHED_RR|SCHED_RESET_ON_FORK worked."); return 0; } #endif - if ((r = pthread_setschedparam(pthread_self(), SCHED_RR, &sp)) == 0) { + if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp) == 0) { pa_log_debug("SCHED_RR worked."); return 0; } @@ -786,7 +786,6 @@ int pa_match(const char *expr, const char *v) { /* Try to parse a boolean string value.*/ int pa_parse_boolean(const char *v) { const char *expr; - int r; pa_assert(v); /* First we check language independant */ @@ -798,12 +797,12 @@ int pa_parse_boolean(const char *v) { /* And then we check language dependant */ if ((expr = nl_langinfo(YESEXPR))) if (expr[0]) - if ((r = pa_match(expr, v)) > 0) + if (pa_match(expr, v) > 0) return 1; if ((expr = nl_langinfo(NOEXPR))) if (expr[0]) - if ((r = pa_match(expr, v)) > 0) + if (pa_match(expr, v) > 0) return 0; errno = EINVAL; @@ -1195,7 +1194,7 @@ char* pa_strip_nl(char *s) { /* Create a temporary lock file and lock it. */ int pa_lock_lockfile(const char *fn) { - int fd = -1; + int fd; pa_assert(fn); for (;;) { @@ -1238,8 +1237,6 @@ int pa_lock_lockfile(const char *fn) { fd = -1; goto fail; } - - fd = -1; } return fd; -- cgit From 31ae7deefa72288b0c250b3ddc68c39e8eb840eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Sep 2009 23:52:58 +0200 Subject: core-util: properly fill in exception array for pa_reset_sigs() (llvm-clang-analyzer) --- src/pulsecore/core-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index d64c7388..7a9f458c 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2404,7 +2404,7 @@ int pa_reset_sigs(int except, ...) { p[i++] = except; while ((sig = va_arg(ap, int)) >= 0) - sig = p[i++]; + p[i++] = sig; } p[i] = -1; -- cgit From 2d9168ceb388cbb6dba49cc3a531921f78ec3295 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Sep 2009 20:58:36 +0200 Subject: Improve TMPDIR handling Patch from 'jnelson', http://pulseaudio.org/ticket/653 --- src/pulsecore/core-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 7a9f458c..690f34c9 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1390,7 +1390,7 @@ static char* make_random_dir(mode_t m) { if (!tmpdir || !pa_is_path_absolute(tmpdir)) tmpdir = "/tmp"; - fn = pa_sprintf_malloc("%s/pulse-XXXXXXXXXXXX", tmpdir); + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", tmpdir); pathlen = strlen(fn); for (;;) { -- cgit From 7b76ea378460bf3e037dff90742f88f74ee70b11 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Sep 2009 21:06:54 +0200 Subject: core-util: unify how we determine the temporary directory --- src/pulsecore/core-util.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 690f34c9..8e98e857 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1378,19 +1378,10 @@ static char* make_random_dir(mode_t m) { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; - const char *tmpdir; char *fn; size_t pathlen; - if (!(tmpdir = getenv("TMPDIR"))) - if (!(tmpdir = getenv("TMP"))) - if (!(tmpdir = getenv("TEMP"))) - tmpdir = getenv("TEMPDIR"); - - if (!tmpdir || !pa_is_path_absolute(tmpdir)) - tmpdir = "/tmp"; - - fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", tmpdir); + fn = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse-XXXXXXXXXXXX", pa_get_temp_dir()); pathlen = strlen(fn); for (;;) { @@ -2854,3 +2845,25 @@ pa_bool_t pa_run_from_build_tree(void) { } #endif + +const char *pa_get_temp_dir(void) { + const char *t; + + if ((t = getenv("TMPDIR")) && + pa_is_path_absolute(t)) + return t; + + if ((t = getenv("TMP")) && + pa_is_path_absolute(t)) + return t; + + if ((t = getenv("TEMP")) && + pa_is_path_absolute(t)) + return t; + + if ((t = getenv("TEMPDIR")) && + pa_is_path_absolute(t)) + return t; + + return "/tmp"; +} -- cgit