admin.vm.Console 714 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. lock="/var/run/qubes/$QREXEC_REQUESTED_TARGET.terminal.lock"
  3. # use temporary file, because env variables deal poorly with \0 inside
  4. tmpfile=$(mktemp)
  5. trap "rm -f $tmpfile" EXIT
  6. qubesd-query -e \
  7. "$QREXEC_REMOTE_DOMAIN" \
  8. "admin.vm.Console" \
  9. "$QREXEC_REQUESTED_TARGET" \
  10. "$1" >$tmpfile
  11. # exit if qubesd returned an error (not '0\0')
  12. if [ "$(head -c 2 $tmpfile | xxd -p)" != "3000" ]; 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"