orion / rpms / dbus

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