mirror of
https://github.com/containers/youki
synced 2026-08-11 13:30:43 +02:00
* libcontainer: handle init sync messages in event loop Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: tidy init message event loop Refine the init message event loop introduced in the previous commit without changing its behavior: - Gate the `FromRawFd`/`OwnedFd` imports behind `libseccomp` and take ownership of the seccomp notify fd inside the `SeccompNotify` arm where it is used, instead of wrapping it for every message at the top of the loop. This drops the `cfg_attr(allow(unused_variables))` workaround. - Extract `build_container_process_state` out of `handle_seccomp_notify`. - Rename `move_network_devices_to_container` to `handle_setup_network_device` for consistency with the other per-message `handle_*` helpers. - Rename the catch-all binding `other` to `unexpected` so it is not confused with the `Message::OtherError` arm. - Trim comments that restated the code. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: simplify init message dispatch Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: clarify init event loop comments Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: unit test init message handlers Add injectable seams to the per-message init handlers so their success and error paths can be unit tested without running the real side effects: - `handle_hook_request_with` takes the hook runner as a closure. - `handle_seccomp_notify_with` takes the listener send as a closure. - `handle_setup_network_device_with` takes the device move as a closure. Cover the handlers with tests for the success path and each reachable error path, asserting that on failure the corresponding done/reply message is not sent to the init process: - hooks: run_hooks failure propagates and HookDone is not sent. - seccomp: missing container state, missing listener path, and listener send failure; SeccompNotifyDone is not sent on failure. - network device: missing devices, missing/invalid network namespace, and device move failure; the address map is not sent on failure. The seccomp EncodeState path is left untested because serializing the container process state cannot realistically fail. Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * fix comment Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * Handle unexpected init messages explicitly Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * Track pending init requests with booleans Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * delete unit test and helper Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: pass narrowed args to init message handlers Standardize the init message handlers on passing only the values they need instead of the whole `ContainerArgs`, matching how `handle_setup_network_device` already works. `handle_hook_request`, `build_container_process_state`, and `handle_seccomp_notify` now take `container` and `container_type` directly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: move build_container_process_state to seccomp_listener The OCI ContainerProcessState is built solely for the seccomp listener, so move `build_container_process_state` from container_main_process.rs into seccomp_listener.rs to keep the seccomp responsibility in one place. Its error cases move with it: `ContainerStateRequired` and `OciStateBuild` are relocated from `ProcessError` to `SeccompListenerError`, and the call site relies on the existing `ProcessError::SeccompListener` conversion. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: unit test build_container_process_state Cover the OCI status mapping (InitContainer -> Creating, TenantContainer -> Running) and the missing-container-state error path. Now that the function takes narrowed arguments, these can be exercised directly without any test-only dependency-injection helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * tweak Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: enforce init request ordering Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: relax init request ordering to a partial order Hooks and network setup requests have no ordering dependency on each other; requiring a total order encoded the init process's incidental execution order as a protocol contract. Track them as an unordered set instead. Seccomp must still come after all other setup requests, since the init process's own syscalls are subject to the container's seccomp policy once the filter is applied, and Ready is only accepted after all setup is done. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: document init request variants Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: convert init messages with TryFrom Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * libcontainer: track init requests by phase Signed-off-by: YamasouA <akiakiskyhand@gmail.com> * ci: rerun checks Signed-off-by: YamasouA <akiakiskyhand@gmail.com> --------- Signed-off-by: YamasouA <akiakiskyhand@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>