diff --git a/common/common.sh b/common/common.sh index 95a0184fc0489eb582863f4846f0f69099bdbad1..6c1522c305696144edcfb5873b6aaf810e94aef4 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 }