2020-11-27 03:15:34 +01:00
|
|
|
#!/bin/bash --
|
|
|
|
set -euo pipefail
|
2019-04-30 11:23:23 +02:00
|
|
|
|
2020-11-27 03:15:34 +01:00
|
|
|
lock="/run/qubes/$QREXEC_REQUESTED_TARGET.terminal.lock"
|
2019-04-30 11:23:23 +02:00
|
|
|
|
2019-06-09 18:03:18 +02:00
|
|
|
# use temporary file, because env variables deal poorly with \0 inside
|
|
|
|
tmpfile=$(mktemp)
|
2020-11-27 03:15:34 +01:00
|
|
|
trap 'rm -f -- "$tmpfile"' EXIT
|
|
|
|
# exit if qubesd returned an error
|
|
|
|
if ! qubesd-query -e --fail -- \
|
2019-06-09 18:03:18 +02:00
|
|
|
"$QREXEC_REMOTE_DOMAIN" \
|
|
|
|
"admin.vm.Console" \
|
|
|
|
"$QREXEC_REQUESTED_TARGET" \
|
2020-11-27 03:15:34 +01:00
|
|
|
${1+"$1"} >"$tmpfile"; then
|
|
|
|
cat -- "$tmpfile"
|
2019-06-09 18:03:18 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-11-27 03:15:34 +01:00
|
|
|
path=$(tail -c +3 -- "$tmpfile")
|
2019-05-11 12:11:31 +02:00
|
|
|
|
2019-04-30 11:23:23 +02:00
|
|
|
# Create an exclusive lock to ensure that multiple qubes cannot access to the same socket
|
|
|
|
# In the case of multiple qrexec calls it returns a specific exit code
|
2019-06-09 18:03:18 +02:00
|
|
|
sudo flock -n -E 200 -x "$lock" socat - OPEN:"$path"
|