aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/initproc.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-20 01:26:41 +0900
committerOphestra <cat@gensokyo.uk>2025-08-20 01:28:31 +0900
commitc81c9a9d75f179988cf858b85fe2de71bf9c2ff4 (patch)
tree157723a3f9a6f8a456fc939a1ef56e8e597d70f3 /container/initproc.go
parent339e4080dce73d372f6111773066b9c84308b6b7 (diff)
container/init: split setup ops into individual files
This significantly increases readability. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/initproc.go')
-rw-r--r--container/initproc.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/container/initproc.go b/container/initproc.go
new file mode 100644
index 00000000..150702ad
--- /dev/null
+++ b/container/initproc.go
@@ -0,0 +1,41 @@
+package container
+
+import (
+ "encoding/gob"
+ "fmt"
+ "os"
+ . "syscall"
+)
+
+func init() { gob.Register(new(MountProcOp)) }
+
+// Proc appends an [Op] that mounts a private instance of proc.
+func (f *Ops) Proc(target *Absolute) *Ops {
+ *f = append(*f, &MountProcOp{target})
+ return f
+}
+
+// MountProcOp mounts a new instance of [FstypeProc] on container path Target.
+type MountProcOp struct {
+ Target *Absolute
+}
+
+func (p *MountProcOp) early(*setupState) error { return nil }
+func (p *MountProcOp) apply(state *setupState) error {
+ if p.Target == nil {
+ return EBADE
+ }
+ target := toSysroot(p.Target.String())
+ if err := os.MkdirAll(target, state.ParentPerm); err != nil {
+ return wrapErrSelf(err)
+ }
+ return wrapErrSuffix(Mount(SourceProc, target, FstypeProc, MS_NOSUID|MS_NOEXEC|MS_NODEV, zeroString),
+ fmt.Sprintf("cannot mount proc on %q:", p.Target.String()))
+}
+
+func (p *MountProcOp) Is(op Op) bool {
+ vp, ok := op.(*MountProcOp)
+ return ok && ((p == nil && vp == nil) || p == vp)
+}
+func (*MountProcOp) prefix() string { return "mounting" }
+func (p *MountProcOp) String() string { return fmt.Sprintf("proc on %q", p.Target) }