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.
This commit is contained in:
Lennart Poettering 2012-05-15 23:13:28 +02:00
parent 7fad67c461
commit 4c195bcc9d

View file

@ -1396,33 +1396,62 @@ int pa_unlock_lockfile(const char *fn, int fd) {
return r; return r;
} }
static char *get_pulse_home(void) { static char *get_config_home(char *home) {
char *h; char *t;
struct stat st;
char *ret = NULL;
if (!(h = pa_get_home_dir_malloc())) { 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;
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."); pa_log_error("Failed to get home directory.");
return NULL; return NULL;
} }
if (stat(h, &st) < 0) { t = check_ours(h);
pa_log_error("Failed to stat home directory %s: %s", h, pa_cstrerror(errno)); if (t < 0 && t != -ENOENT) {
goto finish; pa_log_error("Home directory not accessible: %s", pa_cstrerror(-t));
pa_xfree(h);
return NULL;
} }
#ifdef HAVE_GETUID /* If the old directory exists, use it. */
if (st.st_uid != getuid()) {
pa_log_error("Home directory %s not ours.", h);
errno = EACCES;
goto finish;
}
#endif
ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h); ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
if (access(ret, F_OK) >= 0) {
free(h);
return ret;
}
free(ret);
finish: /* Otherwise go for the XDG compliant directory. */
pa_xfree(h); config_home = get_config_home(h);
free(h);
ret = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", config_home);
free(config_home);
return ret; return ret;
} }