summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-05-15 23:13:28 +0200
committerLennart Poettering <lennart@poettering.net>2012-05-15 23:13:28 +0200
commit4c195bcc9d5e41af6f02dcd7a8aae97c8a0015e8 (patch)
tree6e20a6e387d10e97ada8a58ad8f585f62e23eb50
parent7fad67c46188991c04a42b190349ebb3f4a1756f (diff)
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.
-rw-r--r--src/pulsecore/core-util.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 0305e080..e6c21bea 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;
}