Skip to main content

Module ipc

Module ipc 

Source
Expand description

Cross-platform IPC to QEMU’s monitor (HMP) and QMP endpoints.

Unix: unix-domain sockets. Windows: named pipes (QEMU’s pipe: chardev on the QEMU side, interprocess client on ours). One Stream type, one connect, per-platform QEMU argv — all protocol code above this is transport-agnostic.

Single-client transports (Windows named pipes, and QEMU’s single-slot unix listen backlog while its main loop is busy in hvf init) mean two rules, learned live: never probe-connect (a connect-and-drop occupies the only slot and refuses the real handshake with ECONNREFUSED), and never overlap sessions. Monitor enforces the second: one handle per VM run, shared by reference with every task of that run.

NOTE (Windows): compiled, never run here — no Windows host in this lab. Pipe names and the pipe: argv form follow QEMU docs; expect iteration.

Structs§

Monitor
One HMP session per VM run. Holds the single connection behind a mutex so the VNC handshake, screenshot task, and idle poll of the same run serialize instead of overlapping (fatal on single-client transports). Create after spawn, share by reference (&Monitor) with every task.

Constants§

MON_SOCK_NAME
QMP_SOCK_NAME
SERIAL_LOG_NAME

Functions§

connect
Connect to the endpoint at path: socket path in the VM dir on Unix (filesystem-path name, used verbatim), pipe base name from vm_endpoint on Windows (namespaced name).
endpoint_alive
True when something accepts on the endpoint (i.e. our QEMU is alive). Advisory only: connect-and-drop, so never call it while a Monitor or QMP session to the same endpoint is open on single-client transports (it would steal the slot / report down). All our flows drop sessions before probing — see cmd_stop.
qemu_arg
QEMU -monitor/-qmp arg for path: unix: vs pipe:.
qmp_alive
Backwards-compatible name used across the codebase.
runtime_dir
Runtime dir for sockets: $XDG_RUNTIME_DIR on Linux (RAM, 0700, cleared on reboot), $TMPDIR on macOS (per-user, private). Never the VM dir itself: ~/.cache lives on persistent (sometimes network) storage, and sun_path caps socket paths at 104 bytes on macOS — deep checkouts breach it. Per-VM subdirs preserve isolation.
stale_remove
Remove a stale endpoint. Named pipes aren’t fs entries: no-op there.
vm_endpoint
Transport address for name scoped to vm_dir. Unix: socket file in a per-VM subdir of runtime_dir (private, short, never NFS home — only the dir stem travels, so deep checkouts can’t breach sun_path). Windows: bare pipe base name (flat \\.\pipe\ namespace; qemu_arg adds the prefix for QEMU’s pipe: chardev).

Type Aliases§

Stream
Byte stream to a QEMU endpoint: Unix-domain socket on Unix, named pipe on Windows. One enum from interprocess — no platform branches at use sites.