From 1b9408864f7f575b83b8f822e7551772ccd37009 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 17 Mar 2025 22:36:39 +0900 Subject: sandbox: pass cmd to cancel function This is not usually in scope otherwise. Signed-off-by: Ophestra --- sandbox/container.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sandbox/container.go') diff --git a/sandbox/container.go b/sandbox/container.go index 943c12cc..f45e2311 100644 --- a/sandbox/container.go +++ b/sandbox/container.go @@ -66,7 +66,7 @@ type ( Stdout io.Writer Stderr io.Writer - Cancel func() error + Cancel func(cmd *exec.Cmd) error WaitDelay time.Duration cmd *exec.Cmd @@ -143,7 +143,12 @@ func (p *Container) Start() error { } 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.WaitDelay = p.WaitDelay + if p.Cancel != nil { + p.cmd.Cancel = func() error { return p.Cancel(p.cmd) } + } else { + p.cmd.Cancel = func() error { return p.cmd.Process.Signal(syscall.SIGTERM) } + } p.cmd.Dir = "/" p.cmd.SysProcAttr = &syscall.SysProcAttr{ Setsid: p.Flags&FAllowTTY == 0, -- cgit v1.3.1