sandbox: override underlying command function
Mostly useful for test instrumentation or otherwise nifty environments. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
4230281194
commit
8a4589c25a
@ -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,15 @@ 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
|
||||
},
|
||||
commandContext := exec.CommandContext
|
||||
container := &Container{name: name, ctx: ctx,
|
||||
InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)},
|
||||
RawCommandContext: &commandContext,
|
||||
}
|
||||
container.CommandContext = func(ctx context.Context) (cmd *exec.Cmd) {
|
||||
cmd = (*container.RawCommandContext)(ctx, internal.MustExecutable())
|
||||
cmd.Args = []string{"init"}
|
||||
return
|
||||
}
|
||||
return container
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user