Add signal handler for catching Ctrl-C on hack/e2e

When operating e2e test, hack/e2e.go process creates kubetest process.
To kill the kubetest process when stop e2e test with Ctrl-C, we need
to send the signal to the process because it also creates another
process and it needs to kill it.
This PR adds the signal handler on hack/e2e.go to kill the kubetest
process.

NOTE: https://github.com/kubernetes/test-infra/pull/4154 is the part
      of kubetest.

solve #43051
pull/6/head
Ken'ichi Ohmichi 2017-08-22 12:33:08 -07:00
parent ef7b7ebd9c
commit 122d881c01
1 changed files with 10 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"time"
@ -81,12 +82,21 @@ func main() {
}
func wait(cmd string, args ...string) error {
sigChannel := make(chan os.Signal, 1)
signal.Notify(sigChannel, os.Interrupt)
c := exec.Command(cmd, args...)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Start(); err != nil {
return err
}
go func() {
sig := <-sigChannel
if err := c.Process.Signal(sig); err != nil {
log.Fatalf("could not send %s signal %s: %v", cmd, sig, err)
}
}()
return c.Wait()
}