From ba17bac843ab1c1bbdc3ba1a9eeaf237208f2edf Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 27 Jul 2016 18:11:58 +0100 Subject: [PATCH 1/2] Change process group when sending kill signal Otherwise when the target process is running sudo it ignores the signal. --- test/e2e_node/e2e_service.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/e2e_node/e2e_service.go b/test/e2e_node/e2e_service.go index db56e15cf9a..b66e959cfbb 100644 --- a/test/e2e_node/e2e_service.go +++ b/test/e2e_node/e2e_service.go @@ -372,7 +372,20 @@ func (k *killCmd) Kill() error { const timeout = 10 * time.Second for _, signal := range []string{"-TERM", "-KILL"} { glog.V(2).Infof("Killing process %d (%s) with %s", pid, name, signal) - _, err := exec.Command("sudo", "kill", signal, strconv.Itoa(pid)).Output() + cmd := exec.Command("sudo", "kill", signal, strconv.Itoa(pid)) + + // Run the 'kill' command in a separate process group so sudo doesn't ignore it + attrs := &syscall.SysProcAttr{} + // Hack to set unix-only field without build tags. + setpgidField := reflect.ValueOf(attrs).Elem().FieldByName("Setpgid") + if setpgidField.IsValid() { + setpgidField.Set(reflect.ValueOf(true)) + } else { + return fmt.Errorf("Failed to set Setpgid field (non-unix build)") + } + cmd.SysProcAttr = attrs + + _, err := cmd.Output() if err != nil { glog.Errorf("Error signaling process %d (%s) with %s: %v", pid, name, signal, err) continue From bd8f4ff8cf1b4e876fb7b56255b357e7a0f18c2a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 4 Aug 2016 15:12:29 +0100 Subject: [PATCH 2/2] Send SIGTERM on Pdeathsig to allow child to clean up Also fix the comment to better describe the effect of this code. --- test/e2e_node/e2e_service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e_node/e2e_service.go b/test/e2e_node/e2e_service.go index b66e959cfbb..d02053d7ae2 100644 --- a/test/e2e_node/e2e_service.go +++ b/test/e2e_node/e2e_service.go @@ -295,12 +295,12 @@ func (es *e2eService) startServer(cmd *healthCheckCommand) error { cmd.Cmd.Stdout = outfile cmd.Cmd.Stderr = outfile - // Killing the sudo command should kill the server as well. + // Death of this test process should kill the server as well. attrs := &syscall.SysProcAttr{} // Hack to set linux-only field without build tags. deathSigField := reflect.ValueOf(attrs).Elem().FieldByName("Pdeathsig") if deathSigField.IsValid() { - deathSigField.Set(reflect.ValueOf(syscall.SIGKILL)) + deathSigField.Set(reflect.ValueOf(syscall.SIGTERM)) } else { cmdErrorChan <- fmt.Errorf("Failed to set Pdeathsig field (non-linux build)") return