]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/doc: ignore SIGINT and SIGQUIT
authorMichael Matloob <matloob@golang.org>
Wed, 21 May 2025 16:20:59 +0000 (12:20 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 21 May 2025 20:40:29 +0000 (13:40 -0700)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Michael Matloob <matloob@google.com>

src/cmd/go/internal/base/base.go
src/cmd/go/internal/doc/doc.go

index a2c95fb52f25cbf64df829d66e23350c8994fbf5..83cbad401e2c83d5d28bf48eb2a395cc2b54cca2 100644 (file)
@@ -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.
index 4156284d1d777d16fe7bd146aa7dc99981d8ff9d..7dfa652e155677f65428f29510134eafb63df7bc 100644 (file)
@@ -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)
+       }
 }