summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/core-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r--src/pulsecore/core-util.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 3e5ea492..dde34d7b 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1315,31 +1315,43 @@ static char* make_random_dir(mode_t m) {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
- char fn[24] = "/tmp/pulse-";
+ const char *tmpdir;
+ char *fn;
+ size_t pathlen;
- fn[sizeof(fn)-1] = 0;
+ 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/pulse-XXXXXXXXXXXX", tmpdir);
+ pathlen = strlen(fn);
for (;;) {
- unsigned i;
+ size_t i;
int r;
mode_t u;
int saved_errno;
- for (i = 11; i < sizeof(fn)-1; i++)
+ for (i = pathlen - 12; i < pathlen; i++)
fn[i] = table[rand() % (sizeof(table)-1)];
u = umask((~m) & 0777);
r = mkdir(fn, m);
+
saved_errno = errno;
umask(u);
+ errno = saved_errno;
if (r >= 0)
- return pa_xstrdup(fn);
-
- errno = saved_errno;
+ return fn;
if (errno != EEXIST) {
pa_log_error("Failed to create random directory %s: %s", fn, pa_cstrerror(errno));
+ pa_xfree(fn);
return NULL;
}
}
@@ -1370,6 +1382,7 @@ static int make_random_dir_and_link(mode_t m, const char *k) {
char *pa_get_runtime_dir(void) {
char *d, *k = NULL, *p = NULL, *t = NULL, *mid;
struct stat st;
+ mode_t m;
/* The runtime directory shall contain dynamic data that needs NOT
* to be kept accross reboots and is usuallly private to the user,
@@ -1378,10 +1391,9 @@ char *pa_get_runtime_dir(void) {
* this directory, we link it to a random subdir in /tmp, if it
* was not explicitly configured. */
- if ((d = getenv("PULSE_RUNTIME_PATH"))) {
- mode_t m;
+ m = pa_in_system_mode() ? 0755U : 0700U;
- m = pa_in_system_mode() ? 0755U : 0700U;
+ if ((d = getenv("PULSE_RUNTIME_PATH"))) {
if (pa_make_secure_dir(d, m, (uid_t) -1, (gid_t) -1) < 0) {
pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
@@ -1394,6 +1406,11 @@ char *pa_get_runtime_dir(void) {
if (!(d = get_pulse_home()))
goto fail;
+ if (pa_make_secure_dir(d, m, (uid_t) -1, (gid_t) -1) < 0) {
+ pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
+ goto fail;
+ }
+
if (!(mid = pa_machine_id())) {
pa_xfree(d);
goto fail;
@@ -2334,7 +2351,7 @@ int pa_reset_sigs(int except, ...) {
int pa_reset_sigsv(const int except[]) {
int sig;
- for (sig = 1; sig < _NSIG; sig++) {
+ for (sig = 1; sig < NSIG; sig++) {
pa_bool_t reset = TRUE;
switch (sig) {
@@ -2455,3 +2472,18 @@ char *pa_uname_string(void) {
return pa_sprintf_malloc("%s %s %s %s", u.sysname, u.machine, u.release, u.version);
}
+
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+pa_bool_t pa_in_valgrind(void) {
+ static int b = 0;
+
+ /* To make heisenbugs a bit simpler to find we check for $VALGRIND
+ * here instead of really checking whether we run in valgrind or
+ * not. */
+
+ if (b < 1)
+ b = getenv("VALGRIND") ? 2 : 1;
+
+ return b > 1;
+}
+#endif