mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #44271 from thaJeztah/pidfile_windows_cleanup
pkg/pidfile: windows: replace magic consts for golang.org/x/sys consts
This commit is contained in:
commit
058010187b
1 changed files with 14 additions and 9 deletions
|
@ -4,22 +4,27 @@ import (
|
|||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const (
|
||||
processQueryLimitedInformation = 0x1000
|
||||
|
||||
stillActive = 259
|
||||
)
|
||||
|
||||
func processExists(pid int) bool {
|
||||
h, err := windows.OpenProcess(processQueryLimitedInformation, false, uint32(pid))
|
||||
h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
var c uint32
|
||||
err = windows.GetExitCodeProcess(h, &c)
|
||||
windows.Close(h)
|
||||
_ = windows.CloseHandle(h)
|
||||
if err != nil {
|
||||
return c == stillActive
|
||||
// From the GetExitCodeProcess function (processthreadsapi.h) API docs:
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess
|
||||
//
|
||||
// The GetExitCodeProcess function returns a valid error code defined by the
|
||||
// application only after the thread terminates. Therefore, an application should
|
||||
// not use STILL_ACTIVE (259) as an error code (STILL_ACTIVE is a macro for
|
||||
// STATUS_PENDING (minwinbase.h)). If a thread returns STILL_ACTIVE (259) as
|
||||
// an error code, then applications that test for that value could interpret it
|
||||
// to mean that the thread is still running, and continue to test for the
|
||||
// completion of the thread after the thread has terminated, which could put
|
||||
// the application into an infinite loop.
|
||||
return c == uint32(windows.STATUS_PENDING)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue