From: Michael Pratt Date: Wed, 31 Jan 2024 19:01:12 +0000 (-0500) Subject: runtime/debug: clarify SetCrashOutput dup behavior X-Git-Tag: go1.23rc1~1166 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b27d02c07b7bdb896f279a386fde8cb5ce284ec9;p=gostls13.git runtime/debug: clarify SetCrashOutput dup behavior SetCrashOutput dup's the input file for safety, but I don't think that the docs are very clear about what the caller can/should do with f. "it does not close the previous file" is particularly confusing, as it does close the previous FD (but not the previous passed os.File). Expand and attempt to clarify the explanation, borrowing wording from net.FileConn, which also dup's the input os.File. For #42888. Change-Id: I1c96d2dce7899e335d8f1cd464d2d9b31aeb4e5e Reviewed-on: https://go-review.googlesource.com/c/go/+/559800 Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI --- diff --git a/src/runtime/debug/stack.go b/src/runtime/debug/stack.go index 508afe1f97..7072d29c96 100644 --- a/src/runtime/debug/stack.go +++ b/src/runtime/debug/stack.go @@ -33,9 +33,11 @@ func Stack() []byte { // SetCrashOutput configures a single additional file where unhandled // panics and other fatal errors are printed, in addition to standard error. -// There is only one additional file: calling SetCrashOutput again -// overrides any earlier call; it does not close the previous file. -// SetCrashOutput(nil) disables the use of any additional file. +// There is only one additional file: calling SetCrashOutput again overrides +// any earlier call. +// SetCrashOutput duplicates f's file descriptor, so the caller may safely +// close f as soon as SetCrashOutput returns. +// To disable this additional crash output, call SetCrashOutput(nil). func SetCrashOutput(f *os.File) error { fd := ^uintptr(0) if f != nil {