sandbox: pass cmd to cancel function
This is not usually in scope otherwise. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
cc89dbdf63
commit
1b9408864f
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ func (h *helperContainer) Start() error {
|
|||||||
h.Env = append(h.Env, FortifyStatus+"=1")
|
h.Env = append(h.Env, FortifyStatus+"=1")
|
||||||
|
|
||||||
// stat is populated on fulfill
|
// stat is populated on fulfill
|
||||||
h.Cancel = func() error { return h.stat.Close() }
|
h.Cancel = func(*exec.Cmd) error { return h.stat.Close() }
|
||||||
} else {
|
} else {
|
||||||
h.Env = append(h.Env, FortifyStatus+"=0")
|
h.Env = append(h.Env, FortifyStatus+"=0")
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ type (
|
|||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
Stderr io.Writer
|
Stderr io.Writer
|
||||||
|
|
||||||
Cancel func() error
|
Cancel func(cmd *exec.Cmd) error
|
||||||
WaitDelay time.Duration
|
WaitDelay time.Duration
|
||||||
|
|
||||||
cmd *exec.Cmd
|
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.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.Dir = "/"
|
||||||
p.cmd.SysProcAttr = &syscall.SysProcAttr{
|
p.cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
Setsid: p.Flags&FAllowTTY == 0,
|
Setsid: p.Flags&FAllowTTY == 0,
|
||||||
|
@ -312,10 +312,13 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
|
|||||||
switch {
|
switch {
|
||||||
case w.wstatus.Exited():
|
case w.wstatus.Exited():
|
||||||
r = w.wstatus.ExitStatus()
|
r = w.wstatus.ExitStatus()
|
||||||
|
msg.Verbosef("initial process exited with code %d", w.wstatus.ExitStatus())
|
||||||
case w.wstatus.Signaled():
|
case w.wstatus.Signaled():
|
||||||
r = 128 + int(w.wstatus.Signal())
|
r = 128 + int(w.wstatus.Signal())
|
||||||
|
msg.Verbosef("initial process exited with signal %s", w.wstatus.Signal())
|
||||||
default:
|
default:
|
||||||
r = 255
|
r = 255
|
||||||
|
msg.Verbosef("initial process exited with status %#x", w.wstatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user