//go:build unix
package runner
import (
"os/exec"
"syscall"
"time"
)
// become replaces job-env with the command, under a umask that keeps
// what it writes from everyone outside its group.
func become(path string, argv, env []string) error {
syscall.Umask(0o007)
return syscall.Exec(path, argv, env)
}
// stopTogether puts a command in a process group of its own and, when
// its context ends, kills the whole group: a step's `sleep` or test
// server would otherwise outlive the shell that started it and hold its
// output open, so a stopped task never returned.
func stopTogether(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.Cancel = func() error {
if cmd.Process == nil {
return nil
}
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
cmd.WaitDelay = 5 * time.Second
}