Skip to content

Commit

Permalink
Revert "Fix killing child sudo process in e2e_node tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
fejta authored Jul 27, 2016
1 parent 03fe6b9 commit 12d923e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/e2e_node/e2e_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os/exec"
"path"
"path/filepath"
"reflect"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -294,6 +295,18 @@ 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.
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))
} else {
cmdErrorChan <- fmt.Errorf("Failed to set Pdeathsig field (non-linux build)")
return
}
cmd.Cmd.SysProcAttr = attrs

// Run the command
err = cmd.Run()
if err != nil {
Expand Down Expand Up @@ -359,10 +372,7 @@ 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)
cmd := exec.Command("sudo", "kill", signal, strconv.Itoa(pid))
// Run the 'kill' command in a separate process group so sudo doesn't ignore it
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
_, err := cmd.Output()
_, err := exec.Command("sudo", "kill", signal, strconv.Itoa(pid)).Output()
if err != nil {
glog.Errorf("Error signaling process %d (%s) with %s: %v", pid, name, signal, err)
continue
Expand Down

0 comments on commit 12d923e

Please sign in to comment.