util: hook up pa_get_runtime_dir() with XDG_RUNTIME_DIR

This commit is contained in:
Lennart Poettering 2012-05-15 19:06:53 +02:00
parent 3e9cd3cfcf
commit 7fad67c461

View file

@ -1572,12 +1572,15 @@ char *pa_get_runtime_dir(void) {
* to be kept across reboots and is usually private to the user, * to be kept across reboots and is usually private to the user,
* except in system mode, where it might be accessible by other * except in system mode, where it might be accessible by other
* users, too. Since we need POSIX locking and UNIX sockets in * users, too. Since we need POSIX locking and UNIX sockets in
* this directory, we link it to a random subdir in /tmp, if it * this directory, we try XDG_RUNTIME_DIR first, and if that isn't
* was not explicitly configured. */ * set create a directory in $HOME and link it to a random subdir
* in /tmp, if it was not explicitly configured. */
m = pa_in_system_mode() ? 0755U : 0700U; m = pa_in_system_mode() ? 0755U : 0700U;
if ((d = getenv("PULSE_RUNTIME_PATH"))) { /* Use the explicitly configured value if it is set */
d = getenv("PULSE_RUNTIME_PATH");
if (d) {
if (pa_make_secure_dir(d, m, (uid_t) -1, (gid_t) -1) < 0) { 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)); pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
@ -1587,7 +1590,23 @@ char *pa_get_runtime_dir(void) {
return pa_xstrdup(d); return pa_xstrdup(d);
} }
if (!(d = get_pulse_home())) /* Use the XDG standard for the runtime directory. */
d = getenv("XDG_RUNTIME_DIR");
if (d) {
k = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", d);
if (pa_make_secure_dir(k, m, (uid_t) -1, (gid_t) -1) < 0) {
free(k);
pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
goto fail;
}
return k;
}
/* XDG_RUNTIME_DIR wasn't set, use the old legacy fallback */
d = get_pulse_home();
if (!d)
goto fail; goto fail;
if (pa_make_secure_dir(d, m, (uid_t) -1, (gid_t) -1) < 0) { if (pa_make_secure_dir(d, m, (uid_t) -1, (gid_t) -1) < 0) {
@ -1596,7 +1615,8 @@ char *pa_get_runtime_dir(void) {
goto fail; goto fail;
} }
if (!(mid = pa_machine_id())) { mid = pa_machine_id();
if (!mid) {
pa_xfree(d); pa_xfree(d);
goto fail; goto fail;
} }
@ -1608,7 +1628,8 @@ char *pa_get_runtime_dir(void) {
for (;;) { for (;;) {
/* OK, first let's check if the "runtime" symlink already exists */ /* OK, first let's check if the "runtime" symlink already exists */
if (!(p = pa_readlink(k))) { p = pa_readlink(k);
if (!p) {
if (errno != ENOENT) { if (errno != ENOENT) {
pa_log_error("Failed to stat runtime directory %s: %s", k, pa_cstrerror(errno)); pa_log_error("Failed to stat runtime directory %s: %s", k, pa_cstrerror(errno));
@ -1630,7 +1651,7 @@ char *pa_get_runtime_dir(void) {
} }
#else #else
/* No symlink possible, so let's just create the runtime directly */ /* No symlink possible, so let's just create the runtime directly */
if (!mkdir(k)) if (mkdir(k) < 0)
goto fail; goto fail;
#endif #endif