aboutsummaryrefslogtreecommitdiffhomepage
path: root/sandbox
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-17 22:36:39 +0900
committerOphestra <cat@gensokyo.uk>2025-03-17 22:36:39 +0900
commit1b9408864f7f575b83b8f822e7551772ccd37009 (patch)
treeff1f52b39080386564012cb488e7e1a4864a5eaa /sandbox
parentcc89dbdf63dd8d6025a2158562295a74f923765e (diff)
sandbox: pass cmd to cancel function
This is not usually in scope otherwise. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/container.go9
-rw-r--r--sandbox/init.go3
2 files changed, 10 insertions, 2 deletions
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,
diff --git a/sandbox/init.go b/sandbox/init.go
index 5ebac810..05d66236 100644
--- a/sandbox/init.go
+++ b/sandbox/init.go
@@ -312,10 +312,13 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
switch {
case w.wstatus.Exited():
r = w.wstatus.ExitStatus()
+ msg.Verbosef("initial process exited with code %d", w.wstatus.ExitStatus())
case w.wstatus.Signaled():
r = 128 + int(w.wstatus.Signal())
+ msg.Verbosef("initial process exited with signal %s", w.wstatus.Signal())
default:
r = 255
+ msg.Verbosef("initial process exited with status %#x", w.wstatus)
}
go func() {