Skip to content

Commit 3d20a32

Browse files
committed
runtime: initialize crashFD to -1
crashFD defaults to the zero value of (surprise!) zero. Zero is a valid FD, so on the first call to SetCrashOutput we actually close FD 0 since it is a "valid" FD. Initialize crashFD to -1, the sentinel for "no FD". Change-Id: I3b108c60603f2b83b867cbe079f035c159b6a6ca Reviewed-on: https://go-review.googlesource.com/c/go/+/560776 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 6b0309c commit 3d20a32

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/runtime/proc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ func schedinit() {
775775
}
776776

777777
sched.maxmcount = 10000
778+
crashFD.Store(^uintptr(0))
778779

779780
// The world starts stopped.
780781
worldStopped()

src/runtime/runtime.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func writeErrData(data *byte, n int32) {
244244
// set by debug.SetCrashOutput (see #42888). If it is a valid fd (not
245245
// all ones), writeErr and related functions write to it in addition
246246
// to standard error.
247+
//
248+
// Initialized to -1 in schedinit.
247249
var crashFD atomic.Uintptr
248250

249251
//go:linkname setCrashFD

0 commit comments

Comments
 (0)