admin.vm.Console 701 B

12345678910111213141516171819202122
  1. #!/bin/bash --
  2. set -euo pipefail
  3. lock="/run/qubes/$QREXEC_REQUESTED_TARGET.terminal.lock"
  4. # use temporary file, because env variables deal poorly with \0 inside
  5. tmpfile=$(mktemp)
  6. trap 'rm -f -- "$tmpfile"' EXIT
  7. # exit if qubesd returned an error
  8. if ! qubesd-query -e --fail -- \
  9. "$QREXEC_REMOTE_DOMAIN" \
  10. "admin.vm.Console" \
  11. "$QREXEC_REQUESTED_TARGET" \
  12. ${1+"$1"} >"$tmpfile"; then
  13. cat -- "$tmpfile"
  14. exit 1
  15. fi
  16. path=$(tail -c +3 -- "$tmpfile")
  17. # Create an exclusive lock to ensure that multiple qubes cannot access to the same socket
  18. # In the case of multiple qrexec calls it returns a specific exit code
  19. sudo flock -n -E 200 -x "$lock" socat - OPEN:"$path"