sandbox: check command function pointer
Setting default CommandContext on initialisation is somewhat of a footgun. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
42de09e896
commit
48feca800f
@ -118,7 +118,7 @@ func (p *Container) Start() error {
|
|||||||
return errors.New("sandbox: starting an empty container")
|
return errors.New("sandbox: starting an empty container")
|
||||||
}
|
}
|
||||||
|
|
||||||
c, cancel := context.WithCancel(p.ctx)
|
ctx, cancel := context.WithCancel(p.ctx)
|
||||||
p.cancel = cancel
|
p.cancel = cancel
|
||||||
|
|
||||||
var cloneFlags uintptr = syscall.CLONE_NEWIPC |
|
var cloneFlags uintptr = syscall.CLONE_NEWIPC |
|
||||||
@ -136,7 +136,13 @@ func (p *Container) Start() error {
|
|||||||
p.Gid = OverflowGid()
|
p.Gid = OverflowGid()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.cmd = p.CommandContext(c)
|
if p.CommandContext != nil {
|
||||||
|
p.cmd = p.CommandContext(ctx)
|
||||||
|
} else {
|
||||||
|
p.cmd = exec.CommandContext(ctx, internal.MustExecutable())
|
||||||
|
p.cmd.Args = []string{"init"}
|
||||||
|
}
|
||||||
|
|
||||||
p.cmd.Stdin, p.cmd.Stdout, p.cmd.Stderr = p.Stdin, p.Stdout, p.Stderr
|
p.cmd.Stdin, p.cmd.Stdout, p.cmd.Stderr = p.Stdin, p.Stdout, p.Stderr
|
||||||
p.cmd.Cancel, p.cmd.WaitDelay = p.Cancel, p.WaitDelay
|
p.cmd.Cancel, p.cmd.WaitDelay = p.Cancel, p.WaitDelay
|
||||||
p.cmd.Dir = "/"
|
p.cmd.Dir = "/"
|
||||||
@ -225,10 +231,5 @@ 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,
|
return &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) {
|
|
||||||
cmd = exec.CommandContext(ctx, internal.MustExecutable())
|
|
||||||
cmd.Args = []string{"init"}
|
|
||||||
return
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,13 @@ func ExecFilter(ctx context.Context,
|
|||||||
c, cancel := context.WithTimeout(ctx, lddTimeout)
|
c, cancel := context.WithTimeout(ctx, lddTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
container := sandbox.New(c, "ldd", p)
|
container := sandbox.New(c, "ldd", p)
|
||||||
|
container.CommandContext = commandContext
|
||||||
container.Hostname = "fortify-ldd"
|
container.Hostname = "fortify-ldd"
|
||||||
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
|
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
|
||||||
container.Stdout = stdout
|
container.Stdout = stdout
|
||||||
container.Stderr = stderr
|
container.Stderr = stderr
|
||||||
container.Bind("/", "/", 0).Dev("/dev")
|
container.Bind("/", "/", 0).Dev("/dev")
|
||||||
|
|
||||||
if commandContext != nil {
|
|
||||||
container.CommandContext = commandContext
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if err = container.Serve(); err != nil {
|
} else if err = container.Serve(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user