diff options
| author | Tianon Gravi <admwiggin@gmail.com> | 2022-10-14 18:15:52 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-14 18:15:52 +0000 |
| commit | 96155f626d7fa300fa1f50bcdc84e066cbbd265b (patch) | |
| tree | 57013fa5ff8d973ac9513efaf50d5ae0bc3abd86 /cmd | |
| parent | 6b2328e5ccca941245f984f522eab387850771f2 (diff) | |
| parent | 6176ab5901be80b48624cd3adc6271a90e7551dc (diff) | |
| download | docker-96155f626d7fa300fa1f50bcdc84e066cbbd265b.tar.gz | |
Merge pull request #44286 from thaJeztah/use_SetStdHandle
cmd/dockerd: use golang.org/x/sys/windows.SetStdHandle()
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/dockerd/service_windows.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/cmd/dockerd/service_windows.go b/cmd/dockerd/service_windows.go index 05b9b414f1..530a33653d 100644 --- a/cmd/dockerd/service_windows.go +++ b/cmd/dockerd/service_windows.go @@ -27,9 +27,8 @@ var ( flUnregisterService *bool flRunService *bool - setStdHandle = windows.NewLazySystemDLL("kernel32.dll").NewProc("SetStdHandle") - oldStderr windows.Handle - panicFile *os.File + oldStderr windows.Handle + panicFile *os.File service *handler ) @@ -388,21 +387,19 @@ func initPanicFile(path string) error { // 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 // the panic file. - sh := uint32(windows.STD_ERROR_HANDLE) - h, err := windows.GetStdHandle(sh) + h, err := windows.GetStdHandle(windows.STD_ERROR_HANDLE) if err != nil { return err } - oldStderr = h - r, _, err := setStdHandle.Call(uintptr(sh), uintptr(panicFile.Fd())) - if r == 0 && err != nil { + err = windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(panicFile.Fd())) + if err != nil { return err } // Reset os.Stderr to the panic file (so fmt.Fprintf(os.Stderr,...) actually gets redirected) - os.Stderr = os.NewFile(uintptr(panicFile.Fd()), "/dev/stderr") + os.Stderr = os.NewFile(panicFile.Fd(), "/dev/stderr") // Force threads that panic to write to stderr (the panicFile handle now), otherwise it will go into the ether log.SetOutput(os.Stderr) @@ -413,8 +410,7 @@ func initPanicFile(path string) error { func removePanicFile() { if st, err := panicFile.Stat(); err == nil { if st.Size() == 0 { - sh := uint32(windows.STD_ERROR_HANDLE) - setStdHandle.Call(uintptr(sh), uintptr(oldStderr)) + windows.SetStdHandle(windows.STD_ERROR_HANDLE, oldStderr) panicFile.Close() os.Remove(panicFile.Name()) } |
