runtime/debug: update SetCrashOutput example to not pass parent env vars

Fixes #73490

Change-Id: I500fa73f4215c7f490779f53c1c2c0d775f51a95
Reviewed-on: https://go-review.googlesource.com/c/go/+/667775
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Felix Geisendörfer 2025-04-24 16:38:58 +02:00 committed by Alan Donovan
parent 3452d80da3
commit 3672a09a48

View File

@ -84,7 +84,10 @@ func monitor() {
log.Fatal(err) log.Fatal(err)
} }
cmd := exec.Command(exe, "-test.run=^ExampleSetCrashOutput_monitor$") cmd := exec.Command(exe, "-test.run=^ExampleSetCrashOutput_monitor$")
cmd.Env = append(os.Environ(), monitorVar+"=1") // Be selective in which variables we allow the child to inherit.
// Depending on the application, some may be necessary,
// while others (e.g. GOGC, GOMEMLIMIT) may be harmful; see #73490.
cmd.Env = []string{monitorVar + "=1"}
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Stdout = os.Stderr cmd.Stdout = os.Stderr
pipe, err := cmd.StdinPipe() pipe, err := cmd.StdinPipe()