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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user