]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: initialize crashFD to -1
authorMichael Pratt <mpratt@google.com>
Fri, 2 Feb 2024 18:00:02 +0000 (13:00 -0500)
committerMichael Pratt <mpratt@google.com>
Fri, 2 Feb 2024 18:35:18 +0000 (18:35 +0000)
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 <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/proc.go
src/runtime/runtime.go

index a7a3fb62cb19d444f2f8a8adfcd630cad339cd94..538ed0a282ae01c4333ffea5649ec1bd216f9c52 100644 (file)
@@ -775,6 +775,7 @@ func schedinit() {
        }
 
        sched.maxmcount = 10000
+       crashFD.Store(^uintptr(0))
 
        // The world starts stopped.
        worldStopped()
index 4dfb2f840acaeecefe427df38b18548c85e890fc..c7a511b2a435811f944f25193ec443eb330b899b 100644 (file)
@@ -244,6 +244,8 @@ func writeErrData(data *byte, n int32) {
 // set by debug.SetCrashOutput (see #42888). If it is a valid fd (not
 // all ones), writeErr and related functions write to it in addition
 // to standard error.
+//
+// Initialized to -1 in schedinit.
 var crashFD atomic.Uintptr
 
 //go:linkname setCrashFD