#!/bin/bash # brintos-agent — serve a control channel so a host-side agent can drive this # machine. The host runs run-machine-agent.mjs --control-socket , which # publishes virtio-console port 1; the guest sees it as /dev/vportp1. # # Wire protocol: " \n" in, "\n\n" out. # The mark travels as the FIRST WORD of the request, so a fresh mark per call # can never collide with command output. It cannot be set by the request # itself: eval runs inside $(...) — a subshell — so an assignment made there # would never reach the printf. # # The port is SINGLE-OPEN: one fd, used for both directions. PORT="${1:-/dev/vport1p1}" [ -e "$PORT" ] || { echo "brintos-agent: no $PORT (host did not offer a control port)" >&2; exit 1; } exec 4<>"$PORT" while read -r __m __c <&4; do __o=$(eval "$__c" 2>&1) printf "%s\n%s\n" "$__o" "$__m" >&4 done