containCommand gives a command and its Git children one process group so cancelling a run does not leave a transport or pack process behind. A PTY creates its own session instead.
(cmd *exec.Cmd, terminal bool)
| 14 | // cancelling a run does not leave a transport or pack process behind. A PTY |
| 15 | // creates its own session instead. |
| 16 | func containCommand(cmd *exec.Cmd, terminal bool) { |
| 17 | if !terminal { |
| 18 | cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} |
| 19 | } |
| 20 | cmd.WaitDelay = 5 * time.Second |
| 21 | cmd.Cancel = func() error { |
| 22 | err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) |
| 23 | if errors.Is(err, syscall.ESRCH) { |
| 24 | return os.ErrProcessDone |
| 25 | } |
| 26 | return err |
| 27 | } |
| 28 | } |
no outgoing calls
no test coverage detected