]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: pass signals forward during "go tool"
authorRuss Cox <rsc@golang.org>
Thu, 7 Jan 2021 16:21:37 +0000 (11:21 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 8 Jan 2021 17:13:48 +0000 (17:13 +0000)
This way, if a SIGINT is sent to the go command,
it is forwarded on to the underlying tool.

Otherwise trying to use os.Process.Signal to kill
"go tool compile" only kills the "go tool" not the "compile".

Change-Id: Iac7cd4f06096469f5e76164df813a379c0da3822
Reviewed-on: https://go-review.googlesource.com/c/go/+/282312
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/go/internal/tool/tool.go

index 7f4dc8680211c68c87b2cd4e5bbb1daefcbf7dce..6a755bc43627874a3f789ba4dc7467e12b146c59 100644 (file)
@@ -10,6 +10,7 @@ import (
        "fmt"
        "os"
        "os/exec"
+       "os/signal"
        "sort"
        "strings"
 
@@ -85,7 +86,19 @@ func runTool(ctx context.Context, cmd *base.Command, args []string) {
                Stdout: os.Stdout,
                Stderr: os.Stderr,
        }
-       err := toolCmd.Run()
+       err := toolCmd.Start()
+       if err == nil {
+               c := make(chan os.Signal, 100)
+               signal.Notify(c)
+               go func() {
+                       for sig := range c {
+                               toolCmd.Process.Signal(sig)
+                       }
+               }()
+               err = toolCmd.Wait()
+               signal.Stop(c)
+               close(c)
+       }
        if err != nil {
                // Only print about the exit status if the command
                // didn't even run (not an ExitError) or it didn't exit cleanly