From c81c9a9d75f179988cf858b85fe2de71bf9c2ff4 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 20 Aug 2025 01:26:41 +0900 Subject: container/init: split setup ops into individual files This significantly increases readability. Signed-off-by: Ophestra --- container/initproc.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 container/initproc.go (limited to 'container/initproc.go') 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) } -- cgit v1.3.1