gps: Force subprocesses into new pgroup on unix

This puts us more squarely in control of subprocess signaling.
This commit is contained in:
sam boyer 2017-10-12 22:40:53 -04:00
Родитель bea24e2592
Коммит 6bbd19d908
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -11,6 +11,7 @@ import (
"context" "context"
"os" "os"
"os/exec" "os/exec"
"syscall"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -51,6 +52,17 @@ func (c cmd) CombinedOutput() ([]byte, error) {
var b bytes.Buffer var b bytes.Buffer
c.Cmd.Stdout = &b c.Cmd.Stdout = &b
c.Cmd.Stderr = &b c.Cmd.Stderr = &b
// Force subprocesses into their own process group, rather than being in the
// same process group as the dep process. Ctrl-C sent from a terminal will
// send the signal to the entire running process group, so This allows us to
// directly manage the issuance of signals to subprocesses in that common
// case.
c.Cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
Pgid: 0,
}
if err := c.Cmd.Start(); err != nil { if err := c.Cmd.Start(); err != nil {
return nil, err return nil, err
} }