diff --git a/internal/sandbox/container.go b/internal/sandbox/container.go index 6676a2a..6beb990 100644 --- a/internal/sandbox/container.go +++ b/internal/sandbox/container.go @@ -60,6 +60,8 @@ type ( InitParams // Custom [exec.Cmd] initialisation function. CommandContext func(ctx context.Context) (cmd *exec.Cmd) + // Underlying [exec.CommandContext] function called by CommandContext. + RawCommandContext func(ctx context.Context, name string, args ...string) (cmd *exec.Cmd) // param encoder for shim and init setup *gob.Encoder @@ -220,12 +222,14 @@ func (p *Container) String() string { } func New(ctx context.Context, name string, args ...string) *Container { - return &Container{name: name, ctx: ctx, - InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)}, - CommandContext: func(ctx context.Context) (cmd *exec.Cmd) { - cmd = exec.CommandContext(ctx, internal.MustExecutable()) - cmd.Args = []string{"init"} - return - }, + container := &Container{name: name, ctx: ctx, + InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)}, + RawCommandContext: exec.CommandContext, } + container.CommandContext = func(ctx context.Context) (cmd *exec.Cmd) { + cmd = container.RawCommandContext(ctx, internal.MustExecutable()) + cmd.Args = []string{"init"} + return + } + return container }