2015-02-27 17:51:17 +01:00
|
|
|
// Log the panic under windows to the log file
|
|
|
|
//
|
|
|
|
// Code from minix, via
|
|
|
|
//
|
2017-03-29 14:38:34 +02:00
|
|
|
// https://play.golang.org/p/kLtct7lSUg
|
2015-02-27 17:51:17 +01:00
|
|
|
|
2016-02-24 22:54:21 +01:00
|
|
|
// +build windows
|
2015-02-27 17:51:17 +01:00
|
|
|
|
2017-02-10 14:28:06 +01:00
|
|
|
package fs
|
2015-02-27 17:51:17 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
kernel32 = syscall.MustLoadDLL("kernel32.dll")
|
|
|
|
procSetStdHandle = kernel32.MustFindProc("SetStdHandle")
|
|
|
|
)
|
|
|
|
|
|
|
|
func setStdHandle(stdhandle int32, handle syscall.Handle) error {
|
|
|
|
r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
|
|
|
|
if r0 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
return error(e1)
|
|
|
|
}
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// redirectStderr to the file passed in
|
|
|
|
func redirectStderr(f *os.File) {
|
|
|
|
err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
|
|
|
}
|
|
|
|
}
|