refactor: Extract processExists to util.ProcessExists (gt-560ge)
Move duplicated processExists function to shared util package: - Create internal/util/process.go with ProcessExists function - Add internal/util/process_test.go with basic tests - Update witness/manager.go to use util.ProcessExists - Update refinery/manager.go to use util.ProcessExists - Remove local processExists functions from both files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,7 @@ func (m *Manager) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if w.State == StateRunning && w.PID > 0 && processExists(w.PID) {
|
||||
if w.State == StateRunning && w.PID > 0 && util.ProcessExists(w.PID) {
|
||||
return ErrAlreadyRunning
|
||||
}
|
||||
|
||||
@@ -128,13 +128,3 @@ func (m *Manager) Stop() error {
|
||||
return m.saveState(w)
|
||||
}
|
||||
|
||||
// processExists checks if a process with the given PID exists.
|
||||
func processExists(pid int) bool {
|
||||
proc, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
// On Unix, FindProcess always succeeds; signal 0 tests existence
|
||||
err = proc.Signal(nil)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user