summary refs log tree commit diff
path: root/host
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-02-19 16:37:31 +0000
committerAlyssa Ross <hi@alyssa.is>2022-02-19 16:37:31 +0000
commit9524baba518f5140167376cf07a4ab90f778fc45 (patch)
treeeed719e2f3214fafbb0bd0225daab27061239767 /host
parent58204aedb6ec5a2e4e7bb79cca33eef1d672f476 (diff)
downloadspectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar.gz
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar.bz2
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar.lz
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar.xz
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.tar.zst
spectrum-9524baba518f5140167376cf07a4ab90f778fc45.zip
host/rootfs: vm-console: lock console
If two consoles can be open for the same pty at once, things break
spectacularly, so let's try to prevent that.
Diffstat (limited to 'host')
-rwxr-xr-xhost/rootfs/usr/bin/vm-console12
1 files changed, 11 insertions, 1 deletions
diff --git a/host/rootfs/usr/bin/vm-console b/host/rootfs/usr/bin/vm-console
index 47a5d63..5b688af 100755
--- a/host/rootfs/usr/bin/vm-console
+++ b/host/rootfs/usr/bin/vm-console
@@ -7,4 +7,14 @@ backtick -E pty {
   ch-remote --api-socket /run/service/ext-${1}/env/cloud-hypervisor.sock info
 }
 
-foot -T $1 --pty $pty
+foreground {
+  flock -n $pty
+  foot -T $1 --pty $pty
+}
+importas -iu ? ?
+foreground {
+  if { test $? != 230 }
+  fdmove -c 1 2
+  printf "%s: a console for %s is already open\n" $0 $1
+}
+exit $?