[pulseaudio-commits] 9 commits - src/daemon src/modules src/pulse src/pulsecore src/utils

Tanu Kaskinen tanuk at kemper.freedesktop.org
Tue Jun 24 03:23:36 PDT 2014


 src/daemon/main.c                |    9 ---
 src/daemon/server-lookup.c       |   30 ----------
 src/modules/module-esound-sink.c |   13 ++++
 src/pulse/client-conf.c          |  117 ++++++++++++++++++++-------------------
 src/pulse/client-conf.h          |   11 +--
 src/pulse/context.c              |    9 ---
 src/pulsecore/auth-cookie.c      |    2 
 src/pulsecore/authkey.c          |   62 ++++++--------------
 src/pulsecore/authkey.h          |    3 -
 src/pulsecore/core-util.c        |   77 +++++++++++++++++++------
 src/pulsecore/core-util.h        |    3 +
 src/pulsecore/native-common.h    |    2 
 src/pulsecore/protocol-esound.c  |   15 +++--
 src/pulsecore/protocol-native.c  |    7 ++
 src/utils/pax11publish.c         |   12 ----
 15 files changed, 182 insertions(+), 190 deletions(-)

New commits:
commit 59a8618dcd9128334f31bc5d68c24203f86d5b5e
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:33:01 2014 +0300

    authkey: Use the config home dir for relative paths
    
    Previously relative cookie paths were searched from the home
    directory, now they are searched from the config home directory. This
    fixes the problem that XDG_CONFIG_HOME didn't have effect on cookie
    paths.
    
    BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=75006

diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index c9f5b6e..3c5827d 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -132,29 +132,18 @@ finish:
 }
 
 /* If the specified file path starts with / return it, otherwise
- * return path prepended with home directory */
-static char *normalize_path(const char *fn) {
-
+ * return path prepended with the config home directory. */
+static int normalize_path(const char *fn, char **_r) {
     pa_assert(fn);
+    pa_assert(_r);
 
-#ifndef OS_IS_WIN32
-    if (fn[0] != '/') {
-#else
-    if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
-#endif
-        char *s;
-
-        if (pa_append_to_home_dir(fn, &s) < 0)
-            return NULL;
-
-        return s;
-    }
+    if (!pa_is_path_absolute(fn))
+        return pa_append_to_config_home_dir(fn, _r);
 
-    return pa_xstrdup(fn);
+    *_r = pa_xstrdup(fn);
+    return 0;
 }
 
-/* Load a cookie from a file in the home directory. If the specified
- * path starts with /, use it as absolute path instead. */
 int pa_authkey_load(const char *fn, bool create, void *data, size_t length) {
     char *p;
     int ret;
@@ -163,8 +152,8 @@ int pa_authkey_load(const char *fn, bool create, void *data, size_t length) {
     pa_assert(data);
     pa_assert(length > 0);
 
-    if (!(p = normalize_path(fn)))
-        return -2;
+    if ((ret = normalize_path(fn, &p)) < 0)
+        return ret;
 
     if ((ret = load(p, create, data, length)) < 0)
         pa_log_warn("Failed to load authorization key '%s': %s", p, (ret < 0) ? pa_cstrerror(errno) : "File corrupt");
@@ -177,7 +166,7 @@ int pa_authkey_load(const char *fn, bool create, void *data, size_t length) {
 /* Store the specified cookie in the specified cookie file */
 int pa_authkey_save(const char *fn, const void *data, size_t length) {
     int fd = -1;
-    int unlock = 0, ret = -1;
+    int unlock = 0, ret;
     ssize_t r;
     char *p;
 
@@ -185,11 +174,12 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) {
     pa_assert(data);
     pa_assert(length > 0);
 
-    if (!(p = normalize_path(fn)))
-        return -2;
+    if ((ret = normalize_path(fn, &p)) < 0)
+        return ret;
 
     if ((fd = pa_open_cloexec(p, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) < 0) {
         pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
+        ret = -1;
         goto finish;
     }
 
@@ -197,11 +187,10 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) {
 
     if ((r = pa_loop_write(fd, data, length, NULL)) < 0 || (size_t) r != length) {
         pa_log("Failed to read cookie file '%s': %s", fn, pa_cstrerror(errno));
+        ret = -1;
         goto finish;
     }
 
-    ret = 0;
-
 finish:
 
     if (fd >= 0) {
diff --git a/src/pulsecore/native-common.h b/src/pulsecore/native-common.h
index dad82e0..e7d2970 100644
--- a/src/pulsecore/native-common.h
+++ b/src/pulsecore/native-common.h
@@ -180,7 +180,7 @@ enum {
 };
 
 #define PA_NATIVE_COOKIE_LENGTH 256
-#define PA_NATIVE_COOKIE_FILE ".config/pulse/cookie"
+#define PA_NATIVE_COOKIE_FILE "cookie"
 #define PA_NATIVE_COOKIE_FILE_FALLBACK ".pulse-cookie"
 
 #define PA_NATIVE_DEFAULT_PORT 4713

commit 440f37af00e798ad91580b82e7414d25990b8cce
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:33:00 2014 +0300

    core-util: Add pa_append_to_config_home_dir()

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 1852b1c..1f902f4 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1678,6 +1678,22 @@ int pa_get_config_home_dir(char **_r) {
     return 0;
 }
 
+int pa_append_to_config_home_dir(const char *path, char **_r) {
+    int r;
+    char *config_home_dir;
+
+    pa_assert(path);
+    pa_assert(_r);
+
+    r = pa_get_config_home_dir(&config_home_dir);
+    if (r < 0)
+        return r;
+
+    *_r = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", config_home_dir, path);
+    pa_xfree(config_home_dir);
+    return 0;
+}
+
 char *pa_get_binary_name_malloc(void) {
     char *t;
     size_t allocated = 128;
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index d2ab771..d717299 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -140,6 +140,7 @@ char *pa_get_state_dir(void);
 char *pa_get_home_dir_malloc(void);
 int pa_append_to_home_dir(const char *path, char **_r);
 int pa_get_config_home_dir(char **_r);
+int pa_append_to_config_home_dir(const char *path, char **_r);
 char *pa_get_binary_name_malloc(void);
 char *pa_runtime_path(const char *fn);
 char *pa_state_path(const char *fn, bool prepend_machine_id);

commit 6c5c65a718c8100fbf97132c3c1c4778e9440d18
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:59 2014 +0300

    core-util: Add pa_get_config_home_dir()

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index cef9f88..1852b1c 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1549,16 +1549,6 @@ int pa_unlock_lockfile(const char *fn, int fd) {
     return r;
 }
 
-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;
 
@@ -1576,7 +1566,7 @@ static int check_ours(const char *p) {
 }
 
 static char *get_pulse_home(void) {
-    char *h, *ret, *config_home;
+    char *h, *ret;
     int t;
 
     h = pa_get_home_dir_malloc();
@@ -1594,17 +1584,14 @@ static char *get_pulse_home(void) {
 
     /* 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);
+    pa_xfree(h);
+    if (access(ret, F_OK) >= 0)
         return ret;
-    }
     free(ret);
 
     /* 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);
+    if (pa_get_config_home_dir(&ret) < 0)
+        return NULL;
 
     return ret;
 }
@@ -1670,6 +1657,27 @@ int pa_append_to_home_dir(const char *path, char **_r) {
     return 0;
 }
 
+int pa_get_config_home_dir(char **_r) {
+    const char *e;
+    char *home_dir;
+
+    pa_assert(_r);
+
+    e = getenv("XDG_CONFIG_HOME");
+    if (e && *e) {
+        *_r = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", e);
+        return 0;
+    }
+
+    home_dir = pa_get_home_dir_malloc();
+    if (!home_dir)
+        return -PA_ERR_NOENTITY;
+
+    *_r = pa_sprintf_malloc("%s" PA_PATH_SEP ".config" PA_PATH_SEP "pulse", home_dir);
+    pa_xfree(home_dir);
+    return 0;
+}
+
 char *pa_get_binary_name_malloc(void) {
     char *t;
     size_t allocated = 128;
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 9495e6d..d2ab771 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -139,6 +139,7 @@ char *pa_get_runtime_dir(void);
 char *pa_get_state_dir(void);
 char *pa_get_home_dir_malloc(void);
 int pa_append_to_home_dir(const char *path, char **_r);
+int pa_get_config_home_dir(char **_r);
 char *pa_get_binary_name_malloc(void);
 char *pa_runtime_path(const char *fn);
 char *pa_state_path(const char *fn, bool prepend_machine_id);

commit 14845b2c8e867a20222b6b6a4fd0e52f1b9dc79f
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:58 2014 +0300

    esound, native: Pass an absolute path to pa_authkey_load() when using a file in the home directory
    
    If a relative path is passed to pa_authkey_load(), it will interpret
    the path as relative to the home directory. This is wrong, because
    relative paths should be interpreted to be relative to the config home
    directory. Before fixing pa_authkey_load(), this patch prepares for
    the change by using absolute paths when the file actually needs to be
    in the home directory (i.e. the fallback cookie path for the native
    protocol and the default cookie path for the esound protocol).

diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index f887962..bef3d8e 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -527,6 +527,8 @@ int pa__init(pa_module*m) {
     const char *espeaker;
     uint32_t key;
     pa_sink_new_data data;
+    char *cookie_path;
+    int r;
 
     pa_assert(m);
 
@@ -620,9 +622,18 @@ int pa__init(pa_module*m) {
 
     pa_socket_client_set_callback(u->client, on_connection, u);
 
+    cookie_path = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL));
+    if (!cookie_path) {
+        if (pa_append_to_home_dir(".esd_auth", &cookie_path) < 0)
+            goto fail;
+    }
+
     /* Prepare the initial request */
     u->write_data = pa_xmalloc(u->write_length = ESD_KEY_LEN + sizeof(int32_t));
-    if (pa_authkey_load(pa_modargs_get_value(ma, "cookie", ".esd_auth"), true, u->write_data, ESD_KEY_LEN) < 0) {
+
+    r = pa_authkey_load(cookie_path, true, u->write_data, ESD_KEY_LEN);
+    pa_xfree(cookie_path);
+    if (r < 0) {
         pa_log("Failed to load cookie");
         goto fail;
     }
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index fd1ccbf..317c9f9 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -168,6 +168,7 @@ void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_e
 
 int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length) {
     int r;
+    char *fallback_path;
 
     pa_assert(c);
     pa_assert(cookie);
@@ -213,9 +214,12 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     if (r >= 0)
         return 0;
 
-    r = pa_authkey_load(PA_NATIVE_COOKIE_FILE_FALLBACK, false, cookie, cookie_length);
-    if (r >= 0)
-        return 0;
+    if (pa_append_to_home_dir(PA_NATIVE_COOKIE_FILE_FALLBACK, &fallback_path) > 0) {
+        r = pa_authkey_load(fallback_path, false, cookie, cookie_length);
+        pa_xfree(fallback_path);
+        if (r >= 0)
+            return 0;
+    }
 
     r = pa_authkey_load(PA_NATIVE_COOKIE_FILE, true, cookie, cookie_length);
     if (r >= 0)
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index 7c1b7a2..755109c 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -1707,15 +1707,20 @@ int pa_esound_options_parse(pa_esound_options *o, pa_core *c, pa_modargs *ma) {
         pa_auth_cookie_unref(o->auth_cookie);
 
     if (enabled) {
-        const char *cn;
+        char *cn;
 
         /* The new name for this is 'auth-cookie', for compat reasons
          * we check the old name too */
-        if (!(cn = pa_modargs_get_value(ma, "auth-cookie", NULL)))
-            if (!(cn = pa_modargs_get_value(ma, "cookie", NULL)))
-                cn = DEFAULT_COOKIE_FILE;
+        if (!(cn = pa_xstrdup(pa_modargs_get_value(ma, "auth-cookie", NULL)))) {
+            if (!(cn = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL)))) {
+                if (pa_append_to_home_dir(DEFAULT_COOKIE_FILE, &cn) < 0)
+                    return -1;
+            }
+        }
 
-        if (!(o->auth_cookie = pa_auth_cookie_get(c, cn, true, ESD_KEY_LEN)))
+        o->auth_cookie = pa_auth_cookie_get(c, cn, true, ESD_KEY_LEN);
+        pa_xfree(cn);
+        if (!o->auth_cookie)
             return -1;
 
     } else
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 606bf25..584e1d9 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -5303,7 +5303,12 @@ int pa_native_options_parse(pa_native_options *o, pa_core *c, pa_modargs *ma) {
         else {
             o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE, false, PA_NATIVE_COOKIE_LENGTH);
             if (!o->auth_cookie) {
-                o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE_FALLBACK, false, PA_NATIVE_COOKIE_LENGTH);
+                char *fallback_path;
+
+                if (pa_append_to_home_dir(PA_NATIVE_COOKIE_FILE_FALLBACK, &fallback_path) >= 0) {
+                    o->auth_cookie = pa_auth_cookie_get(c, fallback_path, false, PA_NATIVE_COOKIE_LENGTH);
+                    pa_xfree(fallback_path);
+                }
 
                 if (!o->auth_cookie)
                     o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE, true, PA_NATIVE_COOKIE_LENGTH);

commit 50042da434b28cf8d7fe39debd3f724c1787d6d6
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:57 2014 +0300

    core-util: Add pa_append_to_home_dir()

diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index 406ce2a..c9f5b6e 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -142,14 +142,11 @@ static char *normalize_path(const char *fn) {
 #else
     if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
 #endif
-        char *homedir, *s;
+        char *s;
 
-        if (!(homedir = pa_get_home_dir_malloc()))
+        if (pa_append_to_home_dir(fn, &s) < 0)
             return NULL;
 
-        s = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", homedir, fn);
-        pa_xfree(homedir);
-
         return s;
     }
 
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index afd872f..cef9f88 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1653,6 +1653,23 @@ char *pa_get_home_dir_malloc(void) {
     return homedir;
 }
 
+int pa_append_to_home_dir(const char *path, char **_r) {
+    char *home_dir;
+
+    pa_assert(path);
+    pa_assert(_r);
+
+    home_dir = pa_get_home_dir_malloc();
+    if (!home_dir) {
+        pa_log("Failed to get home directory.");
+        return -PA_ERR_NOENTITY;
+    }
+
+    *_r = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", home_dir, path);
+    pa_xfree(home_dir);
+    return 0;
+}
+
 char *pa_get_binary_name_malloc(void) {
     char *t;
     size_t allocated = 128;
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 9596b97..9495e6d 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -138,6 +138,7 @@ char* pa_find_config_file(const char *global, const char *local, const char *env
 char *pa_get_runtime_dir(void);
 char *pa_get_state_dir(void);
 char *pa_get_home_dir_malloc(void);
+int pa_append_to_home_dir(const char *path, char **_r);
 char *pa_get_binary_name_malloc(void);
 char *pa_runtime_path(const char *fn);
 char *pa_state_path(const char *fn, bool prepend_machine_id);

commit 71ead4989a9f4781aa645906581be68a4cc2e800
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:56 2014 +0300

    authkey: Rename pa_authkey_load_auto() to pa_authkey_load()
    
    pa_authkey_load() was removed earlier, so the _auto suffix isn't
    necessary any more.

diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index 8b74ea4..f887962 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -622,7 +622,7 @@ int pa__init(pa_module*m) {
 
     /* Prepare the initial request */
     u->write_data = pa_xmalloc(u->write_length = ESD_KEY_LEN + sizeof(int32_t));
-    if (pa_authkey_load_auto(pa_modargs_get_value(ma, "cookie", ".esd_auth"), true, u->write_data, ESD_KEY_LEN) < 0) {
+    if (pa_authkey_load(pa_modargs_get_value(ma, "cookie", ".esd_auth"), true, u->write_data, ESD_KEY_LEN) < 0) {
         pa_log("Failed to load cookie");
         goto fail;
     }
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index 8252419..fd1ccbf 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -174,7 +174,7 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     pa_assert(cookie_length > 0);
 
     if (c->cookie_file_from_env) {
-        r = pa_authkey_load_auto(c->cookie_file_from_env, true, cookie, cookie_length);
+        r = pa_authkey_load(c->cookie_file_from_env, true, cookie, cookie_length);
         if (r >= 0)
             return 0;
 
@@ -192,7 +192,7 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     }
 
     if (c->cookie_file_from_application) {
-        r = pa_authkey_load_auto(c->cookie_file_from_application, true, cookie, cookie_length);
+        r = pa_authkey_load(c->cookie_file_from_application, true, cookie, cookie_length);
         if (r >= 0)
             return 0;
 
@@ -201,7 +201,7 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     }
 
     if (c->cookie_file_from_client_conf) {
-        r = pa_authkey_load_auto(c->cookie_file_from_client_conf, true, cookie, cookie_length);
+        r = pa_authkey_load(c->cookie_file_from_client_conf, true, cookie, cookie_length);
         if (r >= 0)
             return 0;
 
@@ -209,15 +209,15 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
                     pa_cstrerror(errno));
     }
 
-    r = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, false, cookie, cookie_length);
+    r = pa_authkey_load(PA_NATIVE_COOKIE_FILE, false, cookie, cookie_length);
     if (r >= 0)
         return 0;
 
-    r = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE_FALLBACK, false, cookie, cookie_length);
+    r = pa_authkey_load(PA_NATIVE_COOKIE_FILE_FALLBACK, false, cookie, cookie_length);
     if (r >= 0)
         return 0;
 
-    r = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, true, cookie, cookie_length);
+    r = pa_authkey_load(PA_NATIVE_COOKIE_FILE, true, cookie, cookie_length);
     if (r >= 0)
         return 0;
 
diff --git a/src/pulsecore/auth-cookie.c b/src/pulsecore/auth-cookie.c
index a3d9ca4..09e73ab 100644
--- a/src/pulsecore/auth-cookie.c
+++ b/src/pulsecore/auth-cookie.c
@@ -69,7 +69,7 @@ pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, bool create, s
 
     pa_assert_se(pa_shared_set(core, t, c) >= 0);
 
-    if (pa_authkey_load_auto(cn, create, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
+    if (pa_authkey_load(cn, create, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
         pa_auth_cookie_unref(c);
         return NULL;
     }
diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index 289e6c6..406ce2a 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -158,7 +158,7 @@ static char *normalize_path(const char *fn) {
 
 /* Load a cookie from a file in the home directory. If the specified
  * path starts with /, use it as absolute path instead. */
-int pa_authkey_load_auto(const char *fn, bool create, void *data, size_t length) {
+int pa_authkey_load(const char *fn, bool create, void *data, size_t length) {
     char *p;
     int ret;
 
diff --git a/src/pulsecore/authkey.h b/src/pulsecore/authkey.h
index ccda1fd..cadf89d 100644
--- a/src/pulsecore/authkey.h
+++ b/src/pulsecore/authkey.h
@@ -24,7 +24,7 @@
 
 #include <sys/types.h>
 
-int pa_authkey_load_auto(const char *fn, bool create, void *data, size_t length);
+int pa_authkey_load(const char *fn, bool create, void *data, size_t length);
 
 int pa_authkey_save(const char *path, const void *data, size_t length);
 
diff --git a/src/utils/pax11publish.c b/src/utils/pax11publish.c
index 8c9ce7d..86336d0 100644
--- a/src/utils/pax11publish.c
+++ b/src/utils/pax11publish.c
@@ -186,7 +186,7 @@ int main(int argc, char *argv[]) {
 
             pa_client_conf_free(conf);
 
-            if (pa_authkey_load_auto(cookie_file, true, cookie, sizeof(cookie)) < 0) {
+            if (pa_authkey_load(cookie_file, true, cookie, sizeof(cookie)) < 0) {
                 fprintf(stderr, _("Failed to load cookie data\n"));
                 goto finish;
             }

commit a54d3577293c55461fd314cdfa86b633588ae0cd
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:55 2014 +0300

    authkey: Remove pa_authkey_load(), it's redundant
    
    The only place where pa_authkey_load() was called was in
    pa_authkey_load_auto(), and the only functionality that
    pa_authkey_load() was to log a warning if load() fails. That log
    message is now in pa_authkey_load_auto(), so pa_authkey_load() has no
    use any more.

diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index 03c0c4b..289e6c6 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -131,20 +131,6 @@ finish:
     return ret;
 }
 
-/* Load a cookie from a cookie file. If the file doesn't exist, create it. */
-int pa_authkey_load(const char *path, bool create, void *data, size_t length) {
-    int ret;
-
-    pa_assert(path);
-    pa_assert(data);
-    pa_assert(length > 0);
-
-    if ((ret = load(path, create, data, length)) < 0)
-        pa_log_warn("Failed to load authorization key '%s': %s", path, (ret < 0) ? pa_cstrerror(errno) : "File corrupt");
-
-    return ret;
-}
-
 /* If the specified file path starts with / return it, otherwise
  * return path prepended with home directory */
 static char *normalize_path(const char *fn) {
@@ -183,7 +169,9 @@ int pa_authkey_load_auto(const char *fn, bool create, void *data, size_t length)
     if (!(p = normalize_path(fn)))
         return -2;
 
-    ret = pa_authkey_load(p, create, data, length);
+    if ((ret = load(p, create, data, length)) < 0)
+        pa_log_warn("Failed to load authorization key '%s': %s", p, (ret < 0) ? pa_cstrerror(errno) : "File corrupt");
+
     pa_xfree(p);
 
     return ret;
diff --git a/src/pulsecore/authkey.h b/src/pulsecore/authkey.h
index df62d0c..ccda1fd 100644
--- a/src/pulsecore/authkey.h
+++ b/src/pulsecore/authkey.h
@@ -24,7 +24,6 @@
 
 #include <sys/types.h>
 
-int pa_authkey_load(const char *path, bool create, void *data, size_t len);
 int pa_authkey_load_auto(const char *fn, bool create, void *data, size_t length);
 
 int pa_authkey_save(const char *path, const void *data, size_t length);

commit 5141188ca8659b19a877cec6c7e6892804a85e26
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:54 2014 +0300

    client-conf: Move x11 and env loading to pa_client_conf_load()
    
    This simplifies the code a bit.

diff --git a/src/daemon/main.c b/src/daemon/main.c
index c5a7d28..f381e8a 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -59,9 +59,6 @@
 #endif
 
 #include <pulse/client-conf.h>
-#ifdef HAVE_X11
-#include <pulse/client-conf-x11.h>
-#endif
 #include <pulse/mainloop.h>
 #include <pulse/mainloop-signal.h>
 #include <pulse/timeval.h>
@@ -325,11 +322,7 @@ static char *check_configured_address(void) {
     char *default_server = NULL;
     pa_client_conf *c = pa_client_conf_new();
 
-    pa_client_conf_load(c);
-#ifdef HAVE_X11
-    pa_client_conf_from_x11(c);
-#endif
-    pa_client_conf_env(c);
+    pa_client_conf_load(c, true, true);
 
     if (c->default_server && *c->default_server)
         default_server = pa_xstrdup(c->default_server);
diff --git a/src/daemon/server-lookup.c b/src/daemon/server-lookup.c
index 6557fb7..c281530 100644
--- a/src/daemon/server-lookup.c
+++ b/src/daemon/server-lookup.c
@@ -125,7 +125,7 @@ static enum get_address_result_t get_address(pa_server_type_t server_type, char
 
     *address = NULL;
 
-    pa_client_conf_load(conf);
+    pa_client_conf_load(conf, false, false);
 
     if (conf->default_dbus_server)
         *address = pa_xstrdup(conf->default_dbus_server);
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index db54743..8252419 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -40,6 +40,10 @@
 
 #include "client-conf.h"
 
+#ifdef HAVE_X11
+#include <client-conf-x11.h>
+#endif
+
 #define DEFAULT_CLIENT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "client.conf"
 #define DEFAULT_CLIENT_CONFIG_FILE_USER "client.conf"
 
@@ -91,7 +95,39 @@ void pa_client_conf_free(pa_client_conf *c) {
     pa_xfree(c);
 }
 
-void pa_client_conf_load(pa_client_conf *c) {
+static void load_env(pa_client_conf *c) {
+    char *e;
+
+    if ((e = getenv(ENV_DEFAULT_SINK))) {
+        pa_xfree(c->default_sink);
+        c->default_sink = pa_xstrdup(e);
+    }
+
+    if ((e = getenv(ENV_DEFAULT_SOURCE))) {
+        pa_xfree(c->default_source);
+        c->default_source = pa_xstrdup(e);
+    }
+
+    if ((e = getenv(ENV_DEFAULT_SERVER))) {
+        pa_xfree(c->default_server);
+        c->default_server = pa_xstrdup(e);
+
+        /* We disable autospawning automatically if a specific server was set */
+        c->autospawn = false;
+    }
+
+    if ((e = getenv(ENV_DAEMON_BINARY))) {
+        pa_xfree(c->daemon_binary);
+        c->daemon_binary = pa_xstrdup(e);
+    }
+
+    if ((e = getenv(ENV_COOKIE_FILE)) && *e) {
+        pa_xfree(c->cookie_file_from_env);
+        c->cookie_file_from_env = pa_xstrdup(e);
+    }
+}
+
+void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_env) {
     FILE *f = NULL;
     char *fn = NULL;
 
@@ -114,12 +150,20 @@ void pa_client_conf_load(pa_client_conf *c) {
     };
 
     f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
-    if (!f)
-        return;
+    if (f) {
+        pa_config_parse(fn, f, table, NULL, NULL);
+        pa_xfree(fn);
+        fclose(f);
+    }
 
-    pa_config_parse(fn, f, table, NULL, NULL);
-    pa_xfree(fn);
-    fclose(f);
+    if (load_from_x11) {
+#ifdef HAVE_X11
+        pa_client_conf_from_x11(c);
+#endif
+    }
+
+    if (load_from_env)
+        load_env(c);
 }
 
 int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length) {
@@ -183,38 +227,6 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     return -1;
 }
 
-void pa_client_conf_env(pa_client_conf *c) {
-    char *e;
-
-    if ((e = getenv(ENV_DEFAULT_SINK))) {
-        pa_xfree(c->default_sink);
-        c->default_sink = pa_xstrdup(e);
-    }
-
-    if ((e = getenv(ENV_DEFAULT_SOURCE))) {
-        pa_xfree(c->default_source);
-        c->default_source = pa_xstrdup(e);
-    }
-
-    if ((e = getenv(ENV_DEFAULT_SERVER))) {
-        pa_xfree(c->default_server);
-        c->default_server = pa_xstrdup(e);
-
-        /* We disable autospawning automatically if a specific server was set */
-        c->autospawn = false;
-    }
-
-    if ((e = getenv(ENV_DAEMON_BINARY))) {
-        pa_xfree(c->daemon_binary);
-        c->daemon_binary = pa_xstrdup(e);
-    }
-
-    if ((e = getenv(ENV_COOKIE_FILE)) && *e) {
-        pa_xfree(c->cookie_file_from_env);
-        c->cookie_file_from_env = pa_xstrdup(e);
-    }
-}
-
 void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file) {
     pa_assert(c);
     pa_assert(!cookie_file || *cookie_file);
diff --git a/src/pulse/client-conf.h b/src/pulse/client-conf.h
index 05a7025..3c7fd7d 100644
--- a/src/pulse/client-conf.h
+++ b/src/pulse/client-conf.h
@@ -47,9 +47,10 @@ typedef struct pa_client_conf {
 pa_client_conf *pa_client_conf_new(void);
 void pa_client_conf_free(pa_client_conf *c);
 
-/* Load the configuration data from the client configuration file, overwriting
- * the current settings in *c. */
-void pa_client_conf_load(pa_client_conf *c);
+/* Load the configuration data from the client configuration file and
+ * optionally from X11 and/or environment variables, overwriting the current
+ * settings in *c. */
+void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_env);
 
 /* Load the cookie from the cookie sources specified in the configuration, or
  * if nothing is specified or none of the sources work, load the cookie from
@@ -57,10 +58,6 @@ void pa_client_conf_load(pa_client_conf *c);
  * returns a negative value and initializes the cookie to all-zeroes. */
 int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length);
 
-/* Load the configuration data from the environment of the current
-   process, overwriting the current settings in *c. */
-void pa_client_conf_env(pa_client_conf *c);
-
 void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file);
 
 #endif
diff --git a/src/pulse/context.c b/src/pulse/context.c
index ce19d91..d908023 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -48,9 +48,6 @@
 #include <pulse/timeval.h>
 #include <pulse/fork-detect.h>
 #include <pulse/client-conf.h>
-#ifdef HAVE_X11
-#include <pulse/client-conf-x11.h>
-#endif
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/i18n.h>
@@ -166,11 +163,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
 #endif
 
     c->conf = pa_client_conf_new();
-    pa_client_conf_load(c->conf);
-#ifdef HAVE_X11
-    pa_client_conf_from_x11(c->conf);
-#endif
-    pa_client_conf_env(c->conf);
+    pa_client_conf_load(c->conf, true, true);
 
     if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {
 
diff --git a/src/utils/pax11publish.c b/src/utils/pax11publish.c
index e4f9943..8c9ce7d 100644
--- a/src/utils/pax11publish.c
+++ b/src/utils/pax11publish.c
@@ -152,8 +152,7 @@ int main(int argc, char *argv[]) {
             char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
             assert(conf);
 
-            pa_client_conf_load(conf);
-            pa_client_conf_env(conf);
+            pa_client_conf_load(conf, false, true);
 
             pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
             pa_x11_del_prop(xcb, screen, "PULSE_SINK");

commit 067e61cb668c426e3a03c54cead2e2102485d5f7
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jun 8 16:32:53 2014 +0300

    client-conf: Don't report failure from pa_client_conf_load()
    
    pa_context already ignored the return value of pa_client_conf_load(),
    so the only places where the return value was not ignored were the
    D-Bus server lookup thing and pax11publish. I don't think those cases
    are negatively affected if they ignore errors in opening or parsing
    client.conf.
    
    pa_client_conf_env() never failed anyway, so returning int was
    obviously redundant.

diff --git a/src/daemon/server-lookup.c b/src/daemon/server-lookup.c
index 1f088e6..6557fb7 100644
--- a/src/daemon/server-lookup.c
+++ b/src/daemon/server-lookup.c
@@ -115,7 +115,6 @@ finish:
 
 enum get_address_result_t {
     SUCCESS,
-    FAILED_TO_LOAD_CLIENT_CONF,
     SERVER_FROM_TYPE_FAILED
 };
 
@@ -126,10 +125,7 @@ static enum get_address_result_t get_address(pa_server_type_t server_type, char
 
     *address = NULL;
 
-    if (pa_client_conf_load(conf) < 0) {
-        r = FAILED_TO_LOAD_CLIENT_CONF;
-        goto finish;
-    }
+    pa_client_conf_load(conf);
 
     if (conf->default_dbus_server)
         *address = pa_xstrdup(conf->default_dbus_server);
@@ -180,18 +176,6 @@ static DBusHandlerResult handle_get_address(DBusConnection *conn, DBusMessage *m
             r = DBUS_HANDLER_RESULT_HANDLED;
             goto finish;
 
-        case FAILED_TO_LOAD_CLIENT_CONF:
-            if (!(reply = dbus_message_new_error(msg, "org.pulseaudio.ClientConfLoadError", "Failed to load client.conf."))) {
-                r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-                goto finish;
-            }
-            if (!dbus_connection_send(conn, reply, NULL)) {
-                r = DBUS_HANDLER_RESULT_NEED_MEMORY;
-                goto finish;
-            }
-            r = DBUS_HANDLER_RESULT_HANDLED;
-            goto finish;
-
         case SERVER_FROM_TYPE_FAILED:
             if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "PulseAudio internal error: get_dbus_server_from_type() failed."))) {
                 r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -398,18 +382,6 @@ static DBusHandlerResult handle_get_all(DBusConnection *conn, DBusMessage *msg,
             r = DBUS_HANDLER_RESULT_HANDLED;
             goto finish;
 
-        case FAILED_TO_LOAD_CLIENT_CONF:
-            if (!(reply = dbus_message_new_error(msg, "org.pulseaudio.ClientConfLoadError", "Failed to load client.conf."))) {
-                r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-                goto finish;
-            }
-            if (!dbus_connection_send(conn, reply, NULL)) {
-                r = DBUS_HANDLER_RESULT_NEED_MEMORY;
-                goto finish;
-            }
-            r = DBUS_HANDLER_RESULT_HANDLED;
-            goto finish;
-
         case SERVER_FROM_TYPE_FAILED:
             if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "PulseAudio internal error: get_dbus_server_from_type() failed."))) {
                 r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index e91e877..db54743 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -91,10 +91,9 @@ void pa_client_conf_free(pa_client_conf *c) {
     pa_xfree(c);
 }
 
-int pa_client_conf_load(pa_client_conf *c) {
+void pa_client_conf_load(pa_client_conf *c) {
     FILE *f = NULL;
     char *fn = NULL;
-    int r = -1;
 
     /* Prepare the configuration parse table */
     pa_config_item table[] = {
@@ -114,19 +113,13 @@ int pa_client_conf_load(pa_client_conf *c) {
         { NULL,                     NULL,                     NULL, NULL },
     };
 
-    if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn)))
-        if (errno != ENOENT)
-            goto finish;
+    f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
+    if (!f)
+        return;
 
-    r = f ? pa_config_parse(fn, f, table, NULL, NULL) : 0;
-
-finish:
+    pa_config_parse(fn, f, table, NULL, NULL);
     pa_xfree(fn);
-
-    if (f)
-        fclose(f);
-
-    return r;
+    fclose(f);
 }
 
 int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length) {
@@ -190,7 +183,7 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
     return -1;
 }
 
-int pa_client_conf_env(pa_client_conf *c) {
+void pa_client_conf_env(pa_client_conf *c) {
     char *e;
 
     if ((e = getenv(ENV_DEFAULT_SINK))) {
@@ -220,8 +213,6 @@ int pa_client_conf_env(pa_client_conf *c) {
         pa_xfree(c->cookie_file_from_env);
         c->cookie_file_from_env = pa_xstrdup(e);
     }
-
-    return 0;
 }
 
 void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file) {
diff --git a/src/pulse/client-conf.h b/src/pulse/client-conf.h
index cf424f5..05a7025 100644
--- a/src/pulse/client-conf.h
+++ b/src/pulse/client-conf.h
@@ -49,7 +49,7 @@ void pa_client_conf_free(pa_client_conf *c);
 
 /* Load the configuration data from the client configuration file, overwriting
  * the current settings in *c. */
-int pa_client_conf_load(pa_client_conf *c);
+void pa_client_conf_load(pa_client_conf *c);
 
 /* Load the cookie from the cookie sources specified in the configuration, or
  * if nothing is specified or none of the sources work, load the cookie from
@@ -59,7 +59,7 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
 
 /* Load the configuration data from the environment of the current
    process, overwriting the current settings in *c. */
-int pa_client_conf_env(pa_client_conf *c);
+void pa_client_conf_env(pa_client_conf *c);
 
 void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file);
 
diff --git a/src/utils/pax11publish.c b/src/utils/pax11publish.c
index f79975d..e4f9943 100644
--- a/src/utils/pax11publish.c
+++ b/src/utils/pax11publish.c
@@ -152,15 +152,8 @@ int main(int argc, char *argv[]) {
             char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
             assert(conf);
 
-            if (pa_client_conf_load(conf) < 0) {
-                fprintf(stderr, _("Failed to load client configuration file.\n"));
-                goto finish;
-            }
-
-            if (pa_client_conf_env(conf) < 0) {
-                fprintf(stderr, _("Failed to read environment configuration data.\n"));
-                goto finish;
-            }
+            pa_client_conf_load(conf);
+            pa_client_conf_env(conf);
 
             pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
             pa_x11_del_prop(xcb, screen, "PULSE_SINK");



More information about the pulseaudio-commits mailing list