Skip to content

Commit 6728118

Browse files
committed
cmd/go: pass signals forward during "go tool"
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 <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent e65c543 commit 6728118

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/cmd/go/internal/tool/tool.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"os/exec"
13+
"os/signal"
1314
"sort"
1415
"strings"
1516

@@ -85,7 +86,19 @@ func runTool(ctx context.Context, cmd *base.Command, args []string) {
8586
Stdout: os.Stdout,
8687
Stderr: os.Stderr,
8788
}
88-
err := toolCmd.Run()
89+
err := toolCmd.Start()
90+
if err == nil {
91+
c := make(chan os.Signal, 100)
92+
signal.Notify(c)
93+
go func() {
94+
for sig := range c {
95+
toolCmd.Process.Signal(sig)
96+
}
97+
}()
98+
err = toolCmd.Wait()
99+
signal.Stop(c)
100+
close(c)
101+
}
89102
if err != nil {
90103
// Only print about the exit status if the command
91104
// didn't even run (not an ExitError) or it didn't exit cleanly

0 commit comments

Comments
 (0)