From e562c67251acf695f8a7ffdb30f00ded3c1c8435 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Date: Fri, 8 Jul 2016 11:57:44 +0200 Subject: [PATCH] common: Only use an existing session bus As soon as there is a dbus user session a session bus should be available. Only verify that this exists (failling if it doesn't) rather then trying to workaround things by autolaunching a new bus. Reviewed-by: Luis Araujo <luis.araujo@collabora.co.uk> Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D3663 --- common/common.sh | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/common/common.sh b/common/common.sh index 95a0184..6c1522c 100644 --- a/common/common.sh +++ b/common/common.sh @@ -155,41 +155,16 @@ arch_is_arm() { [[ $(uname -m) =~ arm.* ]] } -# Try hard to find an existing dbus session bus that can be used by the current -# user, and if none exists, autolaunch one. -# Also, set XDG_RUNTIME_DIR +# Check if a session bus is running otherwise fail ensure_dbus_session() { - local dbus_socket dbus_vars - if [[ -z $DBUS_SESSION_BUS_ADDRESS ]]; then - whine "DBUS_SESSION_BUS_ADDRESS is unset!" - # Check if we have a systemd-managed dbus session bus. Here, a user can - # only access its own session bus, so we can only check this path. - dbus_socket="/run/user/$UID/bus" - if [[ -e ${dbus_socket} ]]; then - export DBUS_SESSION_BUS_ADDRESS="unix:path=${dbus_socket}" - say "Set DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS', continuing" - else - # Maybe we're in SDK, and using a traditional dbus-launch session - # bus which can be detected using DISPLAY - if [[ -z $DISPLAY ]]; then - whine "No X DISPLAY found to get dbus user session! Trying :0" - export DISPLAY=":0" - fi - # Use dbus-launch to find an existing session on DISPLAY, and - # if it doesn't exist, autolaunch one connected to DISPLAY. - dbus_vars=($(dbus-launch --autolaunch $(<"/etc/machine-id"))) - if echo "${dbus_vars[0]}" | grep -q "DBUS_SESSION_BUS_ADDRESS"; then - export "${dbus_vars[0]}" - say "Set DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS', continuing" - else - cry "Unable to ensure a dbus session! Aborting ..." - return 1 - fi - fi + local dbus_socket + + dbus_socket="/run/user/$UID/bus" + if [[ ! -e {dbus_socket} ]]; then + cry "Could not find session bus..." + return 1 fi - # This doesn't get set properly by su/PAM on a serial console - export XDG_RUNTIME_DIR="/run/user/$UID" return 0 } -- GitLab