From 70d37800b7b4dcf85050c1690069d7f6f454761a Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Fri, 13 Feb 2015 13:53:27 -0800 Subject: [PATCH] Simplify usage of os/exec For now, keep the finishRunning() wrapper but use a straight cmd.Run() call instead of the convoluted goroutine trying to catch signals. It turns out that Unix process group handling is enough to interrupt pending processes when stopping the run with something like a Ctrl+C which should be enough. Tested: - Full e2e run with hack/e2e-test.sh, two tests failed but looks like they've been failing before this change. - Started a hack/e2e.go -v -build and interrupted it with Ctrl+C, confirmed that build-release.sh was killed in the process. --- hack/e2e.go | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/hack/e2e.go b/hack/e2e.go index b5d6efa3f78..517e4b32f0f 100644 --- a/hack/e2e.go +++ b/hack/e2e.go @@ -27,7 +27,6 @@ import ( "net/http" "os" "os/exec" - "os/signal" "path" "path/filepath" "strconv" @@ -63,7 +62,6 @@ const ( ) var ( - signals = make(chan os.Signal, 100) // Root directory of the specified cluster version, rather than of where // this script is being run from. versionRoot = *root @@ -86,7 +84,6 @@ type ResultsByTest map[string]TestResult func main() { flag.Parse() - signal.Notify(signals, os.Interrupt) if *isup { status := 1 @@ -295,40 +292,17 @@ func runBashUntil(stepName string, cmd *exec.Cmd) func() { } } -func finishRunningWithOutputs(stepName string, cmd *exec.Cmd) (bool, string, string) { - log.Printf("Running: %v", stepName) - stdout, stderr := bytes.NewBuffer(nil), bytes.NewBuffer(nil) +func finishRunning(stepName string, cmd *exec.Cmd) bool { if *verbose { - cmd.Stdout = io.MultiWriter(os.Stdout, stdout) - cmd.Stderr = io.MultiWriter(os.Stderr, stderr) - } else { - cmd.Stdout = stdout - cmd.Stderr = stderr + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr } - - done := make(chan struct{}) - defer close(done) - go func() { - for { - select { - case <-done: - return - case s := <-signals: - cmd.Process.Signal(s) - } - } - }() - + log.Printf("Running: %v", stepName) if err := cmd.Run(); err != nil { log.Printf("Error running %v: %v", stepName, err) - return false, string(stdout.Bytes()), string(stderr.Bytes()) + return false } - return true, string(stdout.Bytes()), string(stderr.Bytes()) -} - -func finishRunning(stepName string, cmd *exec.Cmd) bool { - result, _, _ := finishRunningWithOutputs(stepName, cmd) - return result + return true } func printBashOutputs(headerprefix, lineprefix, output string, escape bool) {