Standardize daemon detection with tryDaemonLock probe (bd-wgu4)

- Extract lock checking to internal/lockfile package
- Add lock probe in RPC client before connection attempts
- Update daemon discovery to use lock probe
- Eliminates unnecessary connection attempts when socket missing

Closes bd-wgu4

Amp-Thread-ID: https://ampcode.com/threads/T-3b863f21-3af4-49d3-9214-477d904b80fe
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-07 21:02:38 -08:00
parent eeef37f37b
commit ba1b856acb
10 changed files with 280 additions and 5 deletions

View File

@@ -0,0 +1,25 @@
//go:build windows
package lockfile
import (
"golang.org/x/sys/windows"
)
const stillActive = 259
// isProcessRunning checks if a process with the given PID is running
func isProcessRunning(pid int) bool {
handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return false
}
defer windows.CloseHandle(handle)
var code uint32
if err := windows.GetExitCodeProcess(handle, &code); err != nil {
return false
}
return code == stillActive
}