aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-08 04:57:24 +0900
committerOphestra <cat@gensokyo.uk>2025-12-08 04:57:24 +0900
commit5785714b64149c2377cd9697c77162b3e7b37e7d (patch)
tree10ab1713fe8c1d227ce0ffe696fa64f2d337587e
parent422efcf258eb49ecd0d4de8e53adae656696ea56 (diff)
container: call op method right before initial process
This is at a point considered to be already "within" the container. Daemons internal to the container can be started here. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--container/autoetc.go1
-rw-r--r--container/autoroot.go1
-rw-r--r--container/init.go15
-rw-r--r--container/initbind.go1
-rw-r--r--container/initdev.go1
-rw-r--r--container/initmkdir.go1
-rw-r--r--container/initoverlay.go2
-rw-r--r--container/initplace.go1
-rw-r--r--container/initproc.go1
-rw-r--r--container/initremount.go1
-rw-r--r--container/initsymlink.go2
-rw-r--r--container/inittmpfs.go1
12 files changed, 28 insertions, 0 deletions
diff --git a/container/autoetc.go b/container/autoetc.go
index 65ab9a2c..3fd9727e 100644
--- a/container/autoetc.go
+++ b/container/autoetc.go
@@ -59,6 +59,7 @@ func (e *AutoEtcOp) apply(state *setupState, k syscallDispatcher) error {
return nil
}
+func (e *AutoEtcOp) late(*setupState, syscallDispatcher) error { return nil }
func (e *AutoEtcOp) hostPath() *check.Absolute { return fhs.AbsEtc.Append(e.hostRel()) }
func (e *AutoEtcOp) hostRel() string { return ".host/" + e.Prefix }
diff --git a/container/autoroot.go b/container/autoroot.go
index f555acad..09e059d9 100644
--- a/container/autoroot.go
+++ b/container/autoroot.go
@@ -69,6 +69,7 @@ func (r *AutoRootOp) apply(state *setupState, k syscallDispatcher) error {
}
return nil
}
+func (r *AutoRootOp) late(*setupState, syscallDispatcher) error { return nil }
func (r *AutoRootOp) Is(op Op) bool {
vr, ok := op.(*AutoRootOp)
diff --git a/container/init.go b/container/init.go
index fa220f25..e5ca1718 100644
--- a/container/init.go
+++ b/container/init.go
@@ -49,6 +49,8 @@ type (
early(state *setupState, k syscallDispatcher) error
// apply is called in intermediate root.
apply(state *setupState, k syscallDispatcher) error
+ // late is called right before starting the initial process.
+ late(state *setupState, k syscallDispatcher) error
// prefix returns a log message prefix, and whether this Op prints no identifying message on its own.
prefix() (string, bool)
@@ -330,6 +332,19 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
}
k.umask(oldmask)
+ // called right before startup of initial process, all state changes to the
+ // current process is prohibited during late
+ for i, op := range *params.Ops {
+ // ops already checked during early setup
+ if err := op.late(state, k); err != nil {
+ if m, ok := messageFromError(err); ok {
+ k.fatal(msg, m)
+ } else {
+ k.fatalf(msg, "cannot complete op at index %d: %v", i, err)
+ }
+ }
+ }
+
if err := closeSetup(); err != nil {
k.fatalf(msg, "cannot close setup pipe: %v", err)
}
diff --git a/container/initbind.go b/container/initbind.go
index 2e63219b..f91d5086 100644
--- a/container/initbind.go
+++ b/container/initbind.go
@@ -90,6 +90,7 @@ func (b *BindMountOp) apply(state *setupState, k syscallDispatcher) error {
}
return k.bindMount(state, source, target, flags)
}
+func (b *BindMountOp) late(*setupState, syscallDispatcher) error { return nil }
func (b *BindMountOp) Is(op Op) bool {
vb, ok := op.(*BindMountOp)
diff --git a/container/initdev.go b/container/initdev.go
index 89a66138..50df680b 100644
--- a/container/initdev.go
+++ b/container/initdev.go
@@ -126,6 +126,7 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
}
return k.mountTmpfs(SourceTmpfs, devShmPath, MS_NOSUID|MS_NODEV, 0, 01777)
}
+func (d *MountDevOp) late(*setupState, syscallDispatcher) error { return nil }
func (d *MountDevOp) Is(op Op) bool {
vd, ok := op.(*MountDevOp)
diff --git a/container/initmkdir.go b/container/initmkdir.go
index 218d6347..d3c4bbb7 100644
--- a/container/initmkdir.go
+++ b/container/initmkdir.go
@@ -27,6 +27,7 @@ func (m *MkdirOp) early(*setupState, syscallDispatcher) error { return nil }
func (m *MkdirOp) apply(_ *setupState, k syscallDispatcher) error {
return k.mkdirAll(toSysroot(m.Path.String()), m.Perm)
}
+func (m *MkdirOp) late(*setupState, syscallDispatcher) error { return nil }
func (m *MkdirOp) Is(op Op) bool {
vm, ok := op.(*MkdirOp)
diff --git a/container/initoverlay.go b/container/initoverlay.go
index 5692af4e..0c31f8fd 100644
--- a/container/initoverlay.go
+++ b/container/initoverlay.go
@@ -205,6 +205,8 @@ func (o *MountOverlayOp) apply(state *setupState, k syscallDispatcher) error {
return k.mount(SourceOverlay, target, FstypeOverlay, 0, strings.Join(options, check.SpecialOverlayOption))
}
+func (o *MountOverlayOp) late(*setupState, syscallDispatcher) error { return nil }
+
func (o *MountOverlayOp) Is(op Op) bool {
vo, ok := op.(*MountOverlayOp)
return ok && o.Valid() && vo.Valid() &&
diff --git a/container/initplace.go b/container/initplace.go
index fe4b60a6..9974c58b 100644
--- a/container/initplace.go
+++ b/container/initplace.go
@@ -57,6 +57,7 @@ func (t *TmpfileOp) apply(state *setupState, k syscallDispatcher) error {
}
return nil
}
+func (t *TmpfileOp) late(*setupState, syscallDispatcher) error { return nil }
func (t *TmpfileOp) Is(op Op) bool {
vt, ok := op.(*TmpfileOp)
diff --git a/container/initproc.go b/container/initproc.go
index d0df8542..3ecb270a 100644
--- a/container/initproc.go
+++ b/container/initproc.go
@@ -28,6 +28,7 @@ func (p *MountProcOp) apply(state *setupState, k syscallDispatcher) error {
}
return k.mount(SourceProc, target, FstypeProc, MS_NOSUID|MS_NOEXEC|MS_NODEV, zeroString)
}
+func (p *MountProcOp) late(*setupState, syscallDispatcher) error { return nil }
func (p *MountProcOp) Is(op Op) bool {
vp, ok := op.(*MountProcOp)
diff --git a/container/initremount.go b/container/initremount.go
index 9a3217a3..b6d16970 100644
--- a/container/initremount.go
+++ b/container/initremount.go
@@ -26,6 +26,7 @@ func (*RemountOp) early(*setupState, syscallDispatcher) error { return nil }
func (r *RemountOp) apply(state *setupState, k syscallDispatcher) error {
return k.remount(state, toSysroot(r.Target.String()), r.Flags)
}
+func (r *RemountOp) late(*setupState, syscallDispatcher) error { return nil }
func (r *RemountOp) Is(op Op) bool {
vr, ok := op.(*RemountOp)
diff --git a/container/initsymlink.go b/container/initsymlink.go
index 7d722d5b..be0ce2a2 100644
--- a/container/initsymlink.go
+++ b/container/initsymlink.go
@@ -50,6 +50,8 @@ func (l *SymlinkOp) apply(state *setupState, k syscallDispatcher) error {
return k.symlink(l.LinkName, target)
}
+func (l *SymlinkOp) late(*setupState, syscallDispatcher) error { return nil }
+
func (l *SymlinkOp) Is(op Op) bool {
vl, ok := op.(*SymlinkOp)
return ok && l.Valid() && vl.Valid() &&
diff --git a/container/inittmpfs.go b/container/inittmpfs.go
index 23e2a832..fb477236 100644
--- a/container/inittmpfs.go
+++ b/container/inittmpfs.go
@@ -48,6 +48,7 @@ func (t *MountTmpfsOp) apply(_ *setupState, k syscallDispatcher) error {
}
return k.mountTmpfs(t.FSName, toSysroot(t.Path.String()), t.Flags, t.Size, t.Perm)
}
+func (t *MountTmpfsOp) late(*setupState, syscallDispatcher) error { return nil }
func (t *MountTmpfsOp) Is(op Op) bool {
vt, ok := op.(*MountTmpfsOp)