Blame SOURCES/dbus-kill-process-with-session

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