platform: Use new crash log api

This commit is contained in:
世界
2025-12-18 23:12:25 +08:00
parent 750dc9c3e0
commit 4afdf4153a

View File

@@ -5,11 +5,10 @@ package libbox
import ( import (
"os" "os"
"runtime" "runtime"
"runtime/debug"
"golang.org/x/sys/unix"
) )
var stderrFile *os.File var crashOutputFile *os.File
func RedirectStderr(path string) error { func RedirectStderr(path string) error {
if stats, err := os.Stat(path); err == nil && stats.Size() > 0 { if stats, err := os.Stat(path); err == nil && stats.Size() > 0 {
@@ -27,12 +26,12 @@ func RedirectStderr(path string) error {
return err return err
} }
} }
err = unix.Dup2(int(outputFile.Fd()), int(os.Stderr.Fd())) err = debug.SetCrashOutput(outputFile, debug.CrashOptions{})
if err != nil { if err != nil {
outputFile.Close() outputFile.Close()
os.Remove(outputFile.Name()) os.Remove(outputFile.Name())
return err return err
} }
stderrFile = outputFile crashOutputFile = outputFile
return nil return nil
} }