Skip to content

Commit e0c91d7

Browse files
committed
Allow GUIVM clients to know if GUIVM has session
Or if GUID of the client can be found on the server. This script is replicated on qubes-core-qrexec. For: QubesOS/qubes-notification-proxy#13 For: QubesOS/qubes-gui-agent-linux#251 For: QubesOS/qubes-core-admin#757 For: QubesOS/qubes-issues#1512 For: QubesOS/qubes-issues#9940 Fixes: QubesOS/qubes-issues#10443
1 parent 1f542b7 commit e0c91d7

File tree

1 file changed

+74
-7
lines changed

1 file changed

+74
-7
lines changed

qubes-rpc/qubes.WaitForSession

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,80 @@
11
#!/bin/sh
2+
#
3+
# If no argument is provided, wait for the session to start.
4+
# If QREXEC_SERVICE_ARGUMENT=guid, wait for QREXEC_REMOTE_DOMAIN's GUID.
5+
26
set -eu
37

4-
if test "$(qubesdb-read --default=True /qubes-gui-enabled)" = "True"; then
5-
user="$(qubesdb-read /default-user || echo 'user')"
6-
while ! [ -e "/var/run/qubes/qrexec-server.$user.sock" ]; do
7-
sleep 0.1
8+
wait_client_guid(){
9+
qube="${1-}"
10+
# Waits for qubes-guid to become available for a given domain.
11+
if test -z "$qube"; then
12+
echo "QREXEC_REMOTE_DOMAIN variable needs to be set" >&2
13+
exit 1
14+
fi
15+
16+
# Traverse /var/run/qubes/qrexec.NAME -> qrexec.ID symlink
17+
qrexec_name_sock="/var/run/qubes/qrexec.$qube"
18+
if ! test -L "$qrexec_name_sock"; then
19+
echo "$0: $qrexec_name_sock not found, domain might be dead" >&2
20+
exit 1
21+
fi
22+
23+
qrexec_id_sock="$(readlink -e "$qrexec_name_sock")"
24+
if test -z "$qrexec_id_sock"; then
25+
echo "$0: readlink failed for $qrexec_name_sock" >&2
26+
exit 1
27+
fi
28+
29+
# Watch for /var/run/qubes/guid-running.ID
30+
xid="${qrexec_id_sock##*/qrexec.}"
31+
basename="${qrexec_id_sock%/*}"
32+
guid_running="$basename/guid-running.$xid"
33+
while true; do
34+
if test -f "$guid_running"; then
35+
break
36+
fi
37+
38+
if ! test -e "$qrexec_id_sock"; then
39+
echo "$0: $qrexec_id_sock not found, domain might be dead" >&2
40+
exit 1
41+
fi
42+
43+
sleep 0.5
844
done
9-
fi
45+
exit 0
46+
}
47+
48+
wait_self_session(){
49+
if ! command -v qrexec-client >/dev/null &&
50+
test "$(qubesdb-read --default=True /qubes-gui-enabled)" = "True"
51+
then
52+
user="$(qubesdb-read /default-user || echo 'user')"
53+
while ! test -e "/var/run/qubes/qrexec-server.$user.sock"; do
54+
sleep 0.1
55+
done
56+
fi
57+
58+
true "${XDG_RUNTIME_DIR:="/run/user/$(id -u)"}"
59+
true "${DBUS_SESSION_BUS_ADDRESS:="unix:path=${XDG_RUNTIME_DIR}/bus"}"
60+
export DBUS_SESSION_BUS_ADDRESS
61+
systemctl --user --wait --quiet is-system-running
62+
exit 0
63+
}
1064

11-
systemctl --user --wait --quiet is-system-running
65+
main(){
66+
arg="${QREXEC_SERVICE_ARGUMENT-}"
67+
client="${QREXEC_REMOTE_DOMAIN-}"
68+
case "${arg}" in
69+
guid)
70+
wait_client_guid "$client"
71+
;;
72+
"")
73+
wait_self_session
74+
;;
75+
*)
76+
echo "Invalid argument, only allowed value is 'guid'" >&2
77+
esac
78+
}
1279

13-
exit 0
80+
main

0 commit comments

Comments
 (0)