diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-09 19:08:54 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-09 19:08:54 +0900 |
| commit | 02271583fb791987a9406c9ba282c75ff7a0e395 (patch) | |
| tree | 00b35900e1ff7bf4fa5f24e7322a9beb222098b9 /container | |
| parent | ef54b2cd086ee8a3186c9646711d70e226815973 (diff) | |
container: remove PATH lookup behaviour
This is way higher level than the container package and does not even work unless every path is mounted in the exact same location.
This behaviour causes nothing but confusion and problems,
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container')
| -rw-r--r-- | container/container.go | 38 | ||||
| -rw-r--r-- | container/container_test.go | 2 | ||||
| -rw-r--r-- | container/init_test.go | 2 |
3 files changed, 14 insertions, 28 deletions
diff --git a/container/container.go b/container/container.go index ea715d96..54cee25f 100644 --- a/container/container.go +++ b/container/container.go @@ -27,8 +27,6 @@ type ( // Container represents a container environment being prepared or run. // None of [Container] methods are safe for concurrent use. Container struct { - // Name of initial process in the container. - name string // Cgroup fd, nil to disable. Cgroup *int // ExtraFiles passed through to initial process in the container, @@ -190,31 +188,12 @@ func (p *Container) Serve() error { setup := p.setup p.setup = nil - if p.Path != "" && !path.IsAbs(p.Path) { + if !path.IsAbs(p.Path) { p.cancel() return msg.WrapErr(EINVAL, fmt.Sprintf("invalid executable path %q", p.Path)) } - if p.Path == "" { - if p.name == "" { - p.Path = os.Getenv("SHELL") - if !path.IsAbs(p.Path) { - p.cancel() - return msg.WrapErr(EBADE, - "no command specified and $SHELL is invalid") - } - p.name = path.Base(p.Path) - } else if path.IsAbs(p.name) { - p.Path = p.name - } else if v, err := exec.LookPath(p.name); err != nil { - p.cancel() - return msg.WrapErr(err, err.Error()) - } else { - p.Path = v - } - } - if p.SeccompRules == nil { // do not transmit nil p.SeccompRules = make([]seccomp.NativeRule, 0) @@ -251,8 +230,15 @@ func (p *Container) ProcessState() *os.ProcessState { return p.cmd.ProcessState } -func New(ctx context.Context, name string, args ...string) *Container { - return &Container{name: name, ctx: ctx, - Params: Params{Args: append([]string{name}, args...), Dir: FHSRoot, Ops: new(Ops)}, - } +// New returns the address to a new instance of [Container] that requires further initialisation before use. +func New(ctx context.Context) *Container { + return &Container{ctx: ctx, Params: Params{Dir: FHSRoot, Ops: new(Ops)}} +} + +// NewCommand calls [New] and initialises the [Params.Path] and [Params.Args] fields. +func NewCommand(ctx context.Context, pathname, name string, args ...string) *Container { + z := New(ctx) + z.Path = pathname + z.Args = append([]string{name}, args...) + return z } diff --git a/container/container_test.go b/container/container_test.go index 62134f70..10c20659 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -392,7 +392,7 @@ func testContainerCancel( } func TestContainerString(t *testing.T) { - c := container.New(t.Context(), "ldd", "/usr/bin/env") + c := container.NewCommand(t.Context(), "/run/current-system/sw/bin/ldd", "ldd", "/usr/bin/env") c.SeccompFlags |= seccomp.AllowMultiarch c.SeccompRules = seccomp.Preset( seccomp.PresetExt|seccomp.PresetDenyNS|seccomp.PresetDenyTTY, diff --git a/container/init_test.go b/container/init_test.go index 6e99cc09..7716458c 100644 --- a/container/init_test.go +++ b/container/init_test.go @@ -47,7 +47,7 @@ func TestMain(m *testing.M) { } func helperNewContainerLibPaths(ctx context.Context, libPaths *[]string, args ...string) (c *container.Container) { - c = container.New(ctx, helperInnerPath, args...) + c = container.NewCommand(ctx, helperInnerPath, "helper", args...) c.Env = append(c.Env, envDoCheck+"=1") c.Bind(os.Args[0], helperInnerPath, 0) |
