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
989019af10
@ -60,6 +60,8 @@ type (
|
|||||||
InitParams
|
InitParams
|
||||||
// Custom [exec.Cmd] initialisation function.
|
// Custom [exec.Cmd] initialisation function.
|
||||||
CommandContext func(ctx context.Context) (cmd *exec.Cmd)
|
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
|
// param encoder for shim and init
|
||||||
setup *gob.Encoder
|
setup *gob.Encoder
|
||||||
@ -220,12 +222,14 @@ func (p *Container) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(ctx context.Context, name string, args ...string) *Container {
|
func New(ctx context.Context, name string, args ...string) *Container {
|
||||||
return &Container{name: name, ctx: ctx,
|
container := &Container{name: name, ctx: ctx,
|
||||||
InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)},
|
InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)},
|
||||||
CommandContext: func(ctx context.Context) (cmd *exec.Cmd) {
|
RawCommandContext: exec.CommandContext,
|
||||||
cmd = exec.CommandContext(ctx, internal.MustExecutable())
|
}
|
||||||
|
container.CommandContext = func(ctx context.Context) (cmd *exec.Cmd) {
|
||||||
|
cmd = container.RawCommandContext(ctx, internal.MustExecutable())
|
||||||
cmd.Args = []string{"init"}
|
cmd.Args = []string{"init"}
|
||||||
return
|
return
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return container
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user