-
Notifications
You must be signed in to change notification settings - Fork 52
Fix watch status on Windows (#72)
#73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,41 @@ | |
|
|
||
| package watch | ||
|
|
||
| import "errors" | ||
| import ( | ||
| "errors" | ||
| "os" | ||
| "syscall" | ||
| ) | ||
|
|
||
| func processCommandLine(pid int) (string, error) { | ||
| _ = pid | ||
| return "", errors.New("process command line lookup not supported on windows") | ||
| } | ||
|
|
||
| // processAlive reports whether a process with the given PID is currently | ||
| // running. os.Process.Signal(0) is unsupported on Windows — Signal returns an | ||
| // error for any signal other than Kill — so IsRunning cannot use it there. | ||
| // Instead we open the process and check its exit code: a live process reports | ||
| // STILL_ACTIVE. | ||
| func processAlive(pid int) bool { | ||
| if pid <= 0 { | ||
| return false | ||
| } | ||
| const stillActive = 259 // STILL_ACTIVE | ||
| h, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, false, uint32(pid)) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| defer syscall.CloseHandle(h) | ||
| var code uint32 | ||
| if err := syscall.GetExitCodeProcess(h, &code); err != nil { | ||
| return false | ||
| } | ||
| return code == stillActive | ||
| } | ||
|
|
||
| // terminateProcess stops the daemon. Windows has no SIGTERM, so Kill (which | ||
| // maps to TerminateProcess) is the correct mechanism. | ||
| func terminateProcess(proc *os.Process) error { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| return proc.Kill() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
.codemap/watch.pidis stale and Windows has reused that PID for an unrelated live process, this returnstrueeven thoughprocessCommandLineis still unsupported on Windows and no repo/daemon ownership is verified.runWatchSubcommand("start")checkswatchIsRunning(absRoot)before spawning, so that stale file makescodemap watch startrefuse to start a real daemon, whilestatuscan report running/stale state until the user deletes the PID file. Fresh evidence:Stopis now non-destructive, but start/status still rely only on this liveness result.Useful? React with 👍 / 👎.