Repository navigation
exec: Run commands inside a running instance - #18
Merged
Merged
Conversation
kerf exec is about to run a command inside a running instance, the way docker exec does. Booting an instance becomes kerf start, matching docker start. Signed-off-by: Cong Wang <cwang@multikernel.io>
One vsock stream per exec carries length-prefixed frames: OPEN with argv, env, cwd, tty and credentials, then stdio, resize and signal frames, and STARTED, ERROR or EXIT back. Signed-off-by: Cong Wang <cwang@multikernel.io>
Like containerd for kata, names are looked up in the rootfs the host has mounted and only numbers go to the spawn, so kerf-init never parses passwd or group files. Signed-off-by: Cong Wang <cwang@multikernel.io>
A session reads OPEN, forks the command with a pty or pipes, relays stdio as frames with backpressure, forwards resize and signals, and reports EXIT or ERROR. It is built into a session-test harness as well, so the tests drive it over a socketpair without vsock. Signed-off-by: Cong Wang <cwang@multikernel.io>
kerf-init listens on vsock port 1023 next to the entrypoint and forks one session process per connection, so the relay never runs inside PID 1. Only host root can connect: the peer must be CID 0 on a reserved port. Signals move to a signalfd so one poll loop handles reaping, forwarding and accepting. Signed-off-by: Cong Wang <cwang@multikernel.io>
A single writer thread owns the socket so stdin, resize and signal frames never interleave, and the main thread only reads, so output keeps draining while stdin waits on backpressure. Signed-off-by: Cong Wang <cwang@multikernel.io>
kerf exec connects to kerf-init in the instance over the multikernel vsock transport from a reserved port and runs the command docker exec style: -i, -t, -e, -w and -u, exit status passed through. Signed-off-by: Cong Wang <cwang@multikernel.io>
The session stopped reading the socket while stdin it had buffered was unwritten, so a command that does not read its stdin held up SIGNAL, RESIZE and the host's disconnect behind it. The host now keeps at most 64 KiB of stdin unacknowledged and the session acknowledges what it writes or drops with a new STDIN_ACK frame, so the session can always read the socket. Also bound the output drain after the command exits to 100 ms in total, since a background process that keeps writing kept EXIT from ever being sent, and drop buffered stdin when a pty master reports hangup instead of spinning on it. Signed-off-by: Cong Wang <cwang@multikernel.io>
With -it the terminal is raw, and SIGTERM or SIGHUP killed kerf exec without restoring it; both now unwind through the restore path and exit 128 + signal. A closed stdout, as in kerf exec web cat log | head, exits 141 like a command killed by SIGPIPE instead of printing a traceback. Signed-off-by: Cong Wang <cwang@multikernel.io>
A pending connection can go away between poll and accept, which would leave PID 1 blocked in accept and stop reaping and signal forwarding. The listener is non-blocking now. Signed-off-by: Cong Wang <cwang@multikernel.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
kerf execnow runs a command inside a running instance, the waydocker execruns one inside a container. The old boot verb becomeskerf start, matchingdocker start.Design
--image/--rootfs-dirspawn, listens on AF_VSOCK port 1023 over the multikernel transport. It forks one session process per connection, so the relay never runs inside PID 1.-unames are resolved on the host against the instance rootfs, and only numeric uid/gid/groups go to the spawn. Without-uno credential syscalls are made, soCONFIG_MULTIUSER=nspawn kernels work.-t, signals are forwarded to the command, and a host disconnect sends SIGHUP to the command's process group.Testing
session-testharness (not shipped), so CI drives it over a socketpair. This covers pipes, tty and resize, signals, disconnect, concurrency, flow control, background writers and malformed requests.python3 -m pytest -q: 403 passed, 1 skipped (the-uswitch test needs root). pylint is clean.