From 6bf245cf1b8d5e30c051bb6295533d287cb4eda6 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 8 Dec 2025 06:06:19 +0900 Subject: [PATCH] container: pass context as setup state This is useful currently for daemon Op, but could be used for many other things. Signed-off-by: Ophestra --- container/init.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/container/init.go b/container/init.go index e5ca171..c568702 100644 --- a/container/init.go +++ b/container/init.go @@ -1,6 +1,7 @@ package container import ( + "context" "errors" "fmt" "log" @@ -64,6 +65,7 @@ type ( setupState struct { nonrepeatable uintptr *Params + context.Context message.Msg } ) @@ -182,7 +184,9 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { k.fatalf(msg, "cannot make / rslave: %v", optionalErrorUnwrap(err)) } - state := &setupState{Params: ¶ms.Params, Msg: msg} + ctx, cancel := context.WithCancel(context.Background()) + state := &setupState{Params: ¶ms.Params, Msg: msg, Context: ctx} + defer cancel() /* early is called right before pivot_root into intermediate root; this step is mostly for gathering information that would otherwise be difficult to obtain @@ -441,6 +445,9 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { } if w.wpid == cmd.Process.Pid { + // cancel Op context early + cancel() + // start timeout early go func() { time.Sleep(params.AdoptWaitDelay); close(timeout) }()