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