[pulseaudio-commits] 2 commits - src/pulsecore
Lennart Poettering
lennart at kemper.freedesktop.org
Tue May 15 14:14:50 PDT 2012
src/pulsecore/core-util.c | 98 ++++++++++++++++++++++++++++++++++------------
1 file changed, 74 insertions(+), 24 deletions(-)
New commits:
commit 4c195bcc9d5e41af6f02dcd7a8aae97c8a0015e8
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue May 15 23:13:28 2012 +0200
core-util: move configuration home directory from ~/,pulse to ~/.config/pulse to follow XDG basedir spec
If ~/.pulse/ already exists we stick to it in order not to lose
configuration and so that pulse configuration may still be shared across
the network with different PA versions.
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 0305e08..e6c21be 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1396,33 +1396,62 @@ int pa_unlock_lockfile(const char *fn, int fd) {
return r;
}
-static char *get_pulse_home(void) {
- char *h;
+static char *get_config_home(char *home) {
+ char *t;
+
+ t = getenv("XDG_CONFIG_HOME");
+ if (t)
+ return pa_xstrdup(t);
+
+ return pa_sprintf_malloc("%s" PA_PATH_SEP ".config", home);
+}
+
+static int check_ours(const char *p) {
struct stat st;
- char *ret = NULL;
- if (!(h = pa_get_home_dir_malloc())) {
+ pa_assert(p);
+
+ if (stat(p, &st) < 0)
+ return -errno;
+
+#ifdef HAVE_GETUID
+ if (st.st_uid != getuid())
+ return -EACCES;
+#endif
+
+ return 0;
+}
+
+static char *get_pulse_home(void) {
+ char *h, *ret, *config_home;
+ int t;
+
+ h = pa_get_home_dir_malloc();
+ if (!h) {
pa_log_error("Failed to get home directory.");
return NULL;
}
- if (stat(h, &st) < 0) {
- pa_log_error("Failed to stat home directory %s: %s", h, pa_cstrerror(errno));
- goto finish;
- }
-
-#ifdef HAVE_GETUID
- if (st.st_uid != getuid()) {
- pa_log_error("Home directory %s not ours.", h);
- errno = EACCES;
- goto finish;
+ t = check_ours(h);
+ if (t < 0 && t != -ENOENT) {
+ pa_log_error("Home directory not accessible: %s", pa_cstrerror(-t));
+ pa_xfree(h);
+ return NULL;
}
-#endif
+ /* If the old directory exists, use it. */
ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
+ if (access(ret, F_OK) >= 0) {
+ free(h);
+ return ret;
+ }
+ free(ret);
-finish:
- pa_xfree(h);
+ /* Otherwise go for the XDG compliant directory. */
+ config_home = get_config_home(h);
+ free(h);
+ ret = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", config_home);
+ free(config_home);
return ret;
}
commit 7fad67c46188991c04a42b190349ebb3f4a1756f
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue May 15 19:06:53 2012 +0200
util: hook up pa_get_runtime_dir() with XDG_RUNTIME_DIR
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index d896061..0305e08 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1572,12 +1572,15 @@ char *pa_get_runtime_dir(void) {
* to be kept across reboots and is usually private to the user,
* except in system mode, where it might be accessible by other
* users, too. Since we need POSIX locking and UNIX sockets in
- * this directory, we link it to a random subdir in /tmp, if it
- * was not explicitly configured. */
+ * this directory, we try XDG_RUNTIME_DIR first, and if that isn't
+ * 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;
- 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) {
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);
}
- 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;
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;
}
- if (!(mid = pa_machine_id())) {
+ mid = pa_machine_id();
+ if (!mid) {
pa_xfree(d);
goto fail;
}
@@ -1608,7 +1628,8 @@ char *pa_get_runtime_dir(void) {
for (;;) {
/* 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) {
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
/* No symlink possible, so let's just create the runtime directly */
- if (!mkdir(k))
+ if (mkdir(k) < 0)
goto fail;
#endif
More information about the pulseaudio-commits
mailing list