cmd/containerd: use golang.org/x/sys/windows.SetStdHandle()
golang.org/x/sys/windows now implements this, so we can use that instead of a local implementation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8b804c4f81
commit
752bff981a
@ -42,7 +42,6 @@ var (
|
|||||||
logFileFlag string
|
logFileFlag string
|
||||||
|
|
||||||
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||||
setStdHandle = kernel32.NewProc("SetStdHandle")
|
|
||||||
allocConsole = kernel32.NewProc("AllocConsole")
|
allocConsole = kernel32.NewProc("AllocConsole")
|
||||||
oldStderr windows.Handle
|
oldStderr windows.Handle
|
||||||
panicFile *os.File
|
panicFile *os.File
|
||||||
@ -355,27 +354,19 @@ func initPanicFile(path string) error {
|
|||||||
// Update STD_ERROR_HANDLE to point to the panic file so that Go writes to
|
// Update STD_ERROR_HANDLE to point to the panic file so that Go writes to
|
||||||
// it when it panics. Remember the old stderr to restore it before removing
|
// it when it panics. Remember the old stderr to restore it before removing
|
||||||
// the panic file.
|
// the panic file.
|
||||||
sh := uint32(windows.STD_ERROR_HANDLE)
|
h, err := windows.GetStdHandle(windows.STD_ERROR_HANDLE)
|
||||||
h, err := windows.GetStdHandle(sh)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
oldStderr = h
|
oldStderr = h
|
||||||
|
|
||||||
r, _, err := setStdHandle.Call(uintptr(sh), panicFile.Fd())
|
return windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(panicFile.Fd()))
|
||||||
if r == 0 && err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func removePanicFile() {
|
func removePanicFile() {
|
||||||
if st, err := panicFile.Stat(); err == nil {
|
if st, err := panicFile.Stat(); err == nil {
|
||||||
if st.Size() == 0 {
|
if st.Size() == 0 {
|
||||||
sh := uint32(windows.STD_ERROR_HANDLE)
|
windows.SetStdHandle(windows.STD_ERROR_HANDLE, oldStderr)
|
||||||
setStdHandle.Call(uintptr(sh), uintptr(oldStderr))
|
|
||||||
panicFile.Close()
|
panicFile.Close()
|
||||||
os.Remove(panicFile.Name())
|
os.Remove(panicFile.Name())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user