X11: Add xauthority parameter
authorWim Taymans <wtaymans@redhat.com>
Thu, 12 Sep 2019 07:49:40 +0000 (09:49 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Thu, 21 Nov 2019 12:44:09 +0000 (14:44 +0200)
Add an xauthority parameter and use it in the startup script.

Apparently on some systems the X authentication cookie is not stored in
~/.Xauthority but in some dynamic location pointed to by the XAUTHORITY
environment variable. The environment variable therefore needs to be set
in the PulseAudio daemon environment in order to have access to the X
server from the PulseAudio daemon, but the variable is not necessarily
set when starting PulseAudio. For example, systemd starts PulseAudio
outside the X session. The start-pulseaudio-x11 script is run in the
X session, so it has the environment variable available, and can pass it
to the X modules, which then can set the variable in the daemon
environment.

RedHat bug: https://bugzilla.redhat.com/show_bug.cgi?id=1723065
Debian bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593746

Based on patch by Alexander Kurtz <kurtz.alex@googlemail.com>

src/daemon/start-pulseaudio-x11.in
src/modules/x11/module-x11-bell.c
src/modules/x11/module-x11-cork-request.c
src/modules/x11/module-x11-publish.c
src/modules/x11/module-x11-xsmp.c

index 117b1b0..0e84315 100755 (executable)
@@ -19,8 +19,8 @@ set -e
 
 if [ x"$DISPLAY" != x ] ; then
 
-    @PACTL_BINARY@ load-module module-x11-publish "display=$DISPLAY" > /dev/null
-    @PACTL_BINARY@ load-module module-x11-cork-request "display=$DISPLAY" > /dev/null
+    @PACTL_BINARY@ load-module module-x11-publish "display=$DISPLAY xauthority=$XAUTHORITY" > /dev/null
+    @PACTL_BINARY@ load-module module-x11-cork-request "display=$DISPLAY xauthority=$XAUTHORITY" > /dev/null
 
     # KDE plasma versions older than 5.17.0 use module-device-manager's routing API.
     # Check for current plasma version and load module if it's necessary.
@@ -32,6 +32,6 @@ if [ x"$DISPLAY" != x ] ; then
     fi
 
     if [ x"$SESSION_MANAGER" != x ] ; then
-       @PACTL_BINARY@ load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null
+       @PACTL_BINARY@ load-module module-x11-xsmp "display=$DISPLAY xauthority=$XAUTHORITY session_manager=$SESSION_MANAGER" > /dev/null
     fi
 fi
index 0200359..eab1e6c 100644 (file)
@@ -44,6 +44,7 @@ static const char* const valid_modargs[] = {
     "sink",
     "sample",
     "display",
+    "xauthority",
     NULL
 };
 
@@ -125,6 +126,13 @@ int pa__init(pa_module*m) {
     u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
     u->x11_client = NULL;
 
+    if (pa_modargs_get_value(ma, "xauthority", NULL)) {
+        if (setenv("XAUTHORITY", pa_modargs_get_value(ma, "xauthority", NULL), 1)) {
+            pa_log("setenv() for $XAUTHORITY failed");
+            goto fail;
+        }
+    }
+
     if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;
 
index ab391c6..6b1a86b 100644 (file)
@@ -46,6 +46,7 @@ PA_MODULE_USAGE("display=<X11 display>");
 
 static const char* const valid_modargs[] = {
     "display",
+    "xauthority",
     NULL
 };
 
@@ -128,6 +129,13 @@ int pa__init(pa_module *m) {
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->module = m;
 
+    if (pa_modargs_get_value(ma, "xauthority", NULL)) {
+        if (setenv("XAUTHORITY", pa_modargs_get_value(ma, "xauthority", NULL), 1)) {
+            pa_log("setenv() for $XAUTHORITY failed");
+            goto fail;
+        }
+    }
+
     if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;
 
index e6735ec..68adf15 100644 (file)
@@ -56,6 +56,7 @@ static const char* const valid_modargs[] = {
     "sink",
     "source",
     "cookie",
+    "xauthority",
     NULL
 };
 
@@ -156,6 +157,13 @@ int pa__init(pa_module*m) {
     if (!(u->auth_cookie = pa_auth_cookie_get(m->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), true, PA_NATIVE_COOKIE_LENGTH)))
         goto fail;
 
+    if (pa_modargs_get_value(ma, "xauthority", NULL)) {
+        if (setenv("XAUTHORITY", pa_modargs_get_value(ma, "xauthority", NULL), 1)) {
+            pa_log("setenv() for $XAUTHORITY failed");
+            goto fail;
+        }
+    }
+
     if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;
 
index 6f80123..459da13 100644 (file)
@@ -46,6 +46,7 @@ static bool ice_in_use = false;
 static const char* const valid_modargs[] = {
     "session_manager",
     "display",
+    "xauthority",
     NULL
 };
 
@@ -139,6 +140,13 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
+    if (pa_modargs_get_value(ma, "xauthority", NULL)) {
+        if (setenv("XAUTHORITY", pa_modargs_get_value(ma, "xauthority", NULL), 1)) {
+            pa_log("setenv() for $XAUTHORITY failed");
+            goto fail;
+        }
+    }
+
     if (!(u->x11 = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;