From 122d881c01d8e202d9fd9def5608f63496ccbfac Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 22 Aug 2017 12:33:08 -0700 Subject: [PATCH] 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 --- hack/e2e.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hack/e2e.go b/hack/e2e.go index bc58a0ad8c..c016926c4a 100644 --- a/hack/e2e.go +++ b/hack/e2e.go @@ -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() }