List machines¶
Source · io.systemd.Machine · systemd v257+ · Unprivileged
machinectl list over Varlink: stream every container and VM registered
with systemd-machined. It also shows a real-world quirk: machined answers
"nothing registered" with an error rather than an empty stream.
Run it¶
Output (illustrative)
MACHINE CLASS SERVICE UNIT LEADER
web container systemd-nspawn systemd-nspawn@web.service 48213
win11 vm libvirt-qemu machine-qemu-1-win11.scope 50122
2 machines listed.
The code¶
How it works¶
- Empty is an error. With no machines registered,
ListMoreyieldsio.systemd.Machine.NoSuchMachine.errors.Is(err, machine.ErrNoSuchMachine)turns that into "zero machines". - Nested optional structs.
Leaderis a*ProcessID; the example checks fornilbefore readingPID. - Pointers for optional strings, read with
varlink.Deref.