diff --git a/internal/version/signal_notunix.go b/internal/version/signal_notunix.go new file mode 100644 index 00000000..506655d1 --- /dev/null +++ b/internal/version/signal_notunix.go @@ -0,0 +1,14 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build plan9 || windows +// +build plan9 windows + +package version + +import ( + "os" +) + +var signalsToIgnore = []os.Signal{os.Interrupt} diff --git a/internal/version/signal_unix.go b/internal/version/signal_unix.go new file mode 100644 index 00000000..e9b9fb9a --- /dev/null +++ b/internal/version/signal_unix.go @@ -0,0 +1,15 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build aix || darwin || dragonfly || freebsd || js || linux || netbsd || openbsd || solaris +// +build aix darwin dragonfly freebsd js linux netbsd openbsd solaris + +package version + +import ( + "os" + "syscall" +) + +var signalsToIgnore = []os.Signal{os.Interrupt, syscall.SIGQUIT} diff --git a/internal/version/version.go b/internal/version/version.go index 866e4adc..98e5d4a9 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -18,6 +18,7 @@ import ( "net/http" "os" "os/exec" + "os/signal" "os/user" "path" "path/filepath" @@ -64,6 +65,9 @@ func runGo(root string) { newPath += string(filepath.ListSeparator) + p } cmd.Env = dedupEnv(caseInsensitiveEnv, append(os.Environ(), "GOROOT="+root, "PATH="+newPath)) + + handleSignals() + if err := cmd.Run(); err != nil { // TODO: return the same exit status maybe. os.Exit(1) @@ -500,3 +504,9 @@ func dedupEnv(caseInsensitive bool, env []string) []string { } return out } + +func handleSignals() { + // Ensure that signals intended for the child process are not handled by + // this process' runtime (e.g. SIGQUIT). See issue #36976. + signal.Notify(make(chan os.Signal), signalsToIgnore...) +}