From bda455ce780762a21bdfd5642a3fc6a71dea653f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 12 Mar 2017 12:53:13 -0400 Subject: [PATCH] resources: exec: Ignore signals sent to main process When we send a ^C to the main process, our children see it too! This puts them in their own process group so that they're not affected. There's still the matter of properly hooking up the internal exit signal to a proper shutdown, but that's separate. This might mean that there should be a case for an interrupt aspect to the resource API which would allow a second ^C by the engine, to cause a forceful termination by the resource if that resource supported that. --- resources/exec.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/exec.go b/resources/exec.go index 93a319d4..e8483e76 100644 --- a/resources/exec.go +++ b/resources/exec.go @@ -114,6 +114,11 @@ func (obj *ExecRes) Watch() error { } cmd := exec.Command(cmdName, cmdArgs...) //cmd.Dir = "" // look for program in pwd ? + // ignore signals sent to parent process (we're in our own group) + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pgid: 0, + } cmdReader, err := cmd.StdoutPipe() if err != nil { @@ -197,6 +202,11 @@ func (obj *ExecRes) CheckApply(apply bool) (bool, error) { cmdArgs = []string{"-c", obj.IfCmd} } cmd := exec.Command(cmdName, cmdArgs...) + // ignore signals sent to parent process (we're in our own group) + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pgid: 0, + } if err := cmd.Run(); err != nil { // TODO: check exit value return true, nil // don't run @@ -228,6 +238,12 @@ func (obj *ExecRes) CheckApply(apply bool) (bool, error) { } cmd := exec.Command(cmdName, cmdArgs...) //cmd.Dir = "" // look for program in pwd ? + // ignore signals sent to parent process (we're in our own group) + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pgid: 0, + } + var out bytes.Buffer cmd.Stdout = &out