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) }()