Skip to content
quarry Artifact [d9f51efd71]
Login

Artifact [d9f51efd71]

Artifact d9f51efd717633ea41db0f3796258bd255c1f0d212b1ce16988250e9532cb228:


//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)
	}
}