| 1 | //go:build windows |
| 2 | |
| 3 | package cli |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | |
| 8 | "golang.org/x/sys/windows" |
| 9 | ) |
| 10 | |
| 11 | const webInstanceStillActiveExitCode = 259 |
| 12 | |
| 13 | func webAddressInUse(err error) bool { |
| 14 | return errors.Is(err, windows.WSAEADDRINUSE) |
| 15 | } |
| 16 | |
| 17 | func webInstanceProcessAlive(pid int) bool { |
| 18 | if pid <= 0 { |
| 19 | return false |
| 20 | } |
| 21 | handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid)) |
| 22 | if err != nil { |
| 23 | return errors.Is(err, windows.ERROR_ACCESS_DENIED) |
| 24 | } |
| 25 | defer windows.CloseHandle(handle) |
| 26 | var code uint32 |
| 27 | return windows.GetExitCodeProcess(handle, &code) == nil && code == webInstanceStillActiveExitCode |
| 28 | } |
| 29 |