[PATCH 2/9] client-conf: Move x11 and env loading to pa_client_conf_load()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This simplifies the code a bit.
---
 src/daemon/main.c          |  9 +----
 src/daemon/server-lookup.c |  2 +-
 src/pulse/client-conf.c    | 88 ++++++++++++++++++++++++++--------------------
 src/pulse/client-conf.h    | 11 +++---
 src/pulse/context.c        |  9 +----
 src/utils/pax11publish.c   |  3 +-
 6 files changed, 58 insertions(+), 64 deletions(-)

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");
-- 
1.9.3



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux