From 1bb947b2eb62f54dd7ff621f7e1c768c00edd1a7 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 7 Dec 2023 18:02:40 -0500 Subject: runtime/debug: SetCrashOutput sets the FD for fatal panics This feature makes it possible to record unhandled panics in any goroutine through a watchdog process (e.g. the same application forked+exec'd as a child in a special mode) that can process the panic report, for example by sending it to a crash-reporting system such as Go telemetry or Sentry. Fixes #42888 Change-Id: I5aa7be8f726bbc70fc650540bd1a14ab60c62ecb Reviewed-on: https://go-review.googlesource.com/c/go/+/547978 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan Reviewed-by: Russ Cox --- src/runtime/write_err_android.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/runtime/write_err_android.go') diff --git a/src/runtime/write_err_android.go b/src/runtime/write_err_android.go index a876900c95..dd950774cb 100644 --- a/src/runtime/write_err_android.go +++ b/src/runtime/write_err_android.go @@ -34,6 +34,10 @@ const ( var logger loggerType func writeErr(b []byte) { + if len(b) == 0 { + return + } + if logger == unknown { // Use logd if /dev/socket/logdw is available. if v := uintptr(access(&writeLogd[0], 0x02 /* W_OK */)); v == 0 { @@ -45,8 +49,9 @@ func writeErr(b []byte) { } } - // Write to stderr for command-line programs. - write(2, unsafe.Pointer(&b[0]), int32(len(b))) + // Write to stderr for command-line programs, + // and optionally to SetCrashOutput file. + writeErrData(&b[0], int32(len(b))) // Log format: "
\x00\x00" // -- cgit v1.3-5-g9baa