//go:build unix
package zitcli
import (
"os/exec"
"syscall"
)
// OwnGroup runs cmd in a process group of its own and makes its
// cancellation kill the whole group: what zit starts (git, and the ssh
// git starts) as well as zit. Killing zit alone leaves them holding the
// output pipe and the connection.
func OwnGroup(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
prev := cmd.Cancel
cmd.Cancel = func() error {
if prev != nil {
_ = prev()
}
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
}