a0d93f
#!/bin/bash
a0d93f
# This script ensures the dbus-daemon is killed when the session closes.
a0d93f
# It's used by SSH sessions that have X forwarding (since the X display
a0d93f
# may outlive the session in those cases)
a0d93f
[ $# != 1 ] && exit 1
a0d93f
a0d93f
exec >& /dev/null
a0d93f
4a88b0
MONITOR_READY_FILE=$(mktemp dbus-session-monitor.XXXXXX --tmpdir)
4a88b0
4a88b0
trap 'rm -f "${MONITOR_READY_FILE}"; kill -TERM $1; kill -HUP $(jobs -p)' EXIT
a0d93f
a0d93f
export GVFS_DISABLE_FUSE=1
4a88b0
coproc SESSION_MONITOR (gio monitor -f "/run/systemd/sessions/${XDG_SESSION_ID}" "${MONITOR_READY_FILE}")
4a88b0
4a88b0
# Poll until the gio monitor command is actively monitoring
4a88b0
until
4a88b0
    touch "${MONITOR_READY_FILE}"
4a88b0
    read -t 0.5 -u ${SESSION_MONITOR[0]}
4a88b0
do
4a88b0
    continue
4a88b0
done
a0d93f
4a88b0
# Block until the session is closed
a0d93f
while grep -q ^State=active <(loginctl show-session $XDG_SESSION_ID)
a0d93f
do
a0d93f
    read -u ${SESSION_MONITOR[0]}
a0d93f
done