Skip to content
quarry Artifact [abcdda2fdd]
Login

Artifact [abcdda2fdd]

Artifact abcdda2fdd1b78b8b4f67c25b74a444e7116ff3b46660e06d1b1aa91978edd76:


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