From c7a55174dc5b087cdd96524530aa10ed1d39968e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 12 Sep 2019 09:49:40 +0200 Subject: [PATCH] X11: Add xauthority parameter 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 --- src/daemon/start-pulseaudio-x11.in | 6 +++--- src/modules/x11/module-x11-bell.c | 8 ++++++++ src/modules/x11/module-x11-cork-request.c | 8 ++++++++ src/modules/x11/module-x11-publish.c | 8 ++++++++ src/modules/x11/module-x11-xsmp.c | 8 ++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/daemon/start-pulseaudio-x11.in b/src/daemon/start-pulseaudio-x11.in index 117b1b0e1..0e84315c3 100755 --- a/src/daemon/start-pulseaudio-x11.in +++ b/src/daemon/start-pulseaudio-x11.in @@ -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 diff --git a/src/modules/x11/module-x11-bell.c b/src/modules/x11/module-x11-bell.c index 020035984..eab1e6c3a 100644 --- a/src/modules/x11/module-x11-bell.c +++ b/src/modules/x11/module-x11-bell.c @@ -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; diff --git a/src/modules/x11/module-x11-cork-request.c b/src/modules/x11/module-x11-cork-request.c index ab391c66a..6b1a86b9f 100644 --- a/src/modules/x11/module-x11-cork-request.c +++ b/src/modules/x11/module-x11-cork-request.c @@ -46,6 +46,7 @@ PA_MODULE_USAGE("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; diff --git a/src/modules/x11/module-x11-publish.c b/src/modules/x11/module-x11-publish.c index e6735eca0..68adf1574 100644 --- a/src/modules/x11/module-x11-publish.c +++ b/src/modules/x11/module-x11-publish.c @@ -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; diff --git a/src/modules/x11/module-x11-xsmp.c b/src/modules/x11/module-x11-xsmp.c index 6f8012372..459da1302 100644 --- a/src/modules/x11/module-x11-xsmp.c +++ b/src/modules/x11/module-x11-xsmp.c @@ -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;