diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-04-11 18:54:00 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-04-11 18:54:00 +0900 |
| commit | 996790946092a9291eb21e297d1f0f04deab8b42 (patch) | |
| tree | a3a8ff49deb5ed02ae282391720ce9613c2db7b3 /sandbox | |
| parent | c806f43881223a85ad888f434e078dcc68de028d (diff) | |
sandbox: relative autoetc links
This allows nested containers to use autoetc, and increases compatibility with other implementations.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox')
| -rw-r--r-- | sandbox/ops.go | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/sandbox/ops.go b/sandbox/ops.go index fd56f617..de105ee6 100644 --- a/sandbox/ops.go +++ b/sandbox/ops.go @@ -443,31 +443,26 @@ func (f *Ops) PlaceP(name string, dataP **[]byte) *Ops { func init() { gob.Register(new(AutoEtc)) } -// AutoEtc creates a toplevel symlink mirror of a directory in sysroot with /etc semantics. +// AutoEtc expands host /etc into a toplevel symlink mirror with /etc semantics. // This is not a generic setup op. It is implemented here to reduce ipc overhead. -type AutoEtc struct { - // this is an absolute path within sysroot - HostEtc string -} +type AutoEtc struct{ Prefix string } func (e *AutoEtc) early(*Params) error { return nil } func (e *AutoEtc) apply(*Params) error { - if !path.IsAbs(e.HostEtc) { - return msg.WrapErr(syscall.EBADE, - fmt.Sprintf("path %q is not absolute", e.HostEtc)) - } - const target = sysrootPath + "/etc/" + rel := e.hostRel() + "/" + if err := os.MkdirAll(target, 0755); err != nil { return wrapErrSelf(err) } - - if d, err := os.ReadDir(toSysroot(e.HostEtc)); err != nil { + if d, err := os.ReadDir(toSysroot(e.hostPath())); err != nil { return wrapErrSelf(err) } else { for _, ent := range d { n := ent.Name() switch n { + case ".host": + case "passwd": case "group": @@ -477,7 +472,7 @@ func (e *AutoEtc) apply(*Params) error { } default: - if err = os.Symlink(path.Join(e.HostEtc, n), target+n); err != nil { + if err = os.Symlink(rel+n, target+n); err != nil { return wrapErrSelf(err) } } @@ -486,11 +481,19 @@ func (e *AutoEtc) apply(*Params) error { return nil } +func (e *AutoEtc) hostPath() string { return "/etc/" + e.hostRel() } +func (e *AutoEtc) hostRel() string { return ".host/" + e.Prefix } func (e *AutoEtc) Is(op Op) bool { ve, ok := op.(*AutoEtc) return ok && ((e == nil && ve == nil) || (e != nil && ve != nil && *e == *ve)) } -func (*AutoEtc) prefix() string { return "setting up" } -func (e *AutoEtc) String() string { return fmt.Sprintf("auto etc via %s", e.HostEtc) } -func (f *Ops) Etc(host string) *Ops { *f = append(*f, &AutoEtc{host}); return f } +func (*AutoEtc) prefix() string { return "setting up" } +func (e *AutoEtc) String() string { return fmt.Sprintf("auto etc %s", e.Prefix) } +func (f *Ops) Etc(host, prefix string) *Ops { + e := &AutoEtc{prefix} + f.Mkdir("/etc", 0755) + f.Bind(host, e.hostPath(), 0) + *f = append(*f, e) + return f +} |
