aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-08 06:06:19 +0900
committerOphestra <cat@gensokyo.uk>2025-12-08 06:06:19 +0900
commit6bf245cf1b8d5e30c051bb6295533d287cb4eda6 (patch)
treebceaf4dea2659d43910c80f6d055a9f48a46b734
parentc8eeb4a4d122189dadb093839c5b98188db9be31 (diff)
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 <cat@gensokyo.uk>
-rw-r--r--container/init.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/container/init.go b/container/init.go
index e5ca1718..c5687025 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: &params.Params, Msg: msg}
+ ctx, cancel := context.WithCancel(context.Background())
+ state := &setupState{Params: &params.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) }()