2019-04-30 11:23:23 +02:00
#!/bin/bash
2019-05-11 12:31:23 +02:00
# TODO: handle 'admin-permission' event for qubesd
2019-04-30 11:23:23 +02:00
lock="/var/run/qubes/$QREXEC_REQUESTED_TARGET.terminal.lock"
2019-05-11 12:11:31 +02:00
qvm-check --quiet --running "$QREXEC_REQUESTED_TARGET" > /dev/null 2>&1 || { echo "Error: domain '$QREXEC_REQUESTED_TARGET' does not exist or is not running"; exit 1; }
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
sudo flock -n -E 200 -x "$lock" socat - OPEN:"$(virsh -c xen ttyconsole "$QREXEC_REQUESTED_TARGET")"