mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-30 16:04:23 +03:00
35 lines
649 B
Go
35 lines
649 B
Go
//go:build darwin || linux
|
|
|
|
package libbox
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"runtime/debug"
|
|
)
|
|
|
|
func RedirectStderr(path string) error {
|
|
if stats, err := os.Stat(path); err == nil && stats.Size() > 0 {
|
|
_ = os.Rename(path, path+".old")
|
|
}
|
|
outputFile, err := os.Create(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if runtime.GOOS != "android" {
|
|
err = outputFile.Chown(sUserID, sGroupID)
|
|
if err != nil {
|
|
outputFile.Close()
|
|
os.Remove(outputFile.Name())
|
|
return err
|
|
}
|
|
}
|
|
err = debug.SetCrashOutput(outputFile, debug.CrashOptions{})
|
|
if err != nil {
|
|
outputFile.Close()
|
|
os.Remove(outputFile.Name())
|
|
return err
|
|
}
|
|
return outputFile.Close()
|
|
}
|