From 50484d3b4e691d361d009d5e4a07c182b35471a0 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 21 May 2025 12:20:59 -0400 Subject: [PATCH] cmd/go/internal/doc: ignore SIGINT and SIGQUIT Just like we do in cmd/doc when we start pkgsite, ignore SIGINT (and SIGQUIT on unix) when we start cmd/doc so that it's handled by cmd/doc (if pkgsite is not started, and before it is started) or pkgsite, if it is started. Also exit with the exit status of the command, rather than using base.Errorf so that we don't print an extra error message to the terminal. For #68106 Change-Id: If968e88b95031761432d13dc47c5febe3391945d Reviewed-on: https://go-review.googlesource.com/c/go/+/675076 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Matloob Reviewed-by: Jonathan Amsterdam Auto-Submit: Michael Matloob --- src/cmd/go/internal/base/base.go | 16 ++++++++++++---- src/cmd/go/internal/doc/doc.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/cmd/go/internal/base/base.go b/src/cmd/go/internal/base/base.go index a2c95fb52f..83cbad401e 100644 --- a/src/cmd/go/internal/base/base.go +++ b/src/cmd/go/internal/base/base.go @@ -191,20 +191,28 @@ func GetExitStatus() int { // connected to the go command's own stdout and stderr. // If the command fails, Run reports the error using Errorf. func Run(cmdargs ...any) { + if err := RunErr(cmdargs...); err != nil { + Errorf("%v", err) + } +} + +// Run runs the command, with stdout and stderr +// connected to the go command's own stdout and stderr. +// If the command fails, RunErr returns the error, which +// may be an *exec.ExitError. +func RunErr(cmdargs ...any) error { cmdline := str.StringList(cmdargs...) if cfg.BuildN || cfg.BuildX { fmt.Printf("%s\n", strings.Join(cmdline, " ")) if cfg.BuildN { - return + return nil } } cmd := exec.Command(cmdline[0], cmdline[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - Errorf("%v", err) - } + return cmd.Run() } // RunStdin is like run but connects Stdin. It retries if it encounters an ETXTBSY. diff --git a/src/cmd/go/internal/doc/doc.go b/src/cmd/go/internal/doc/doc.go index 4156284d1d..7dfa652e15 100644 --- a/src/cmd/go/internal/doc/doc.go +++ b/src/cmd/go/internal/doc/doc.go @@ -9,6 +9,9 @@ import ( "cmd/go/internal/base" "cmd/go/internal/cfg" "context" + "errors" + "os" + "os/exec" "path/filepath" ) @@ -131,5 +134,13 @@ Flags: } func runDoc(ctx context.Context, cmd *base.Command, args []string) { - base.Run(cfg.BuildToolexec, filepath.Join(cfg.GOROOTbin, "go"), "tool", "doc", args) + base.StartSigHandlers() + err := base.RunErr(cfg.BuildToolexec, filepath.Join(cfg.GOROOTbin, "go"), "tool", "doc", args) + if err != nil { + var ee *exec.ExitError + if errors.As(err, &ee) { + os.Exit(ee.ExitCode()) + } + base.Error(err) + } } -- 2.50.0