feat: merge pull request #23 from burakgizlice/fix/stale-pid-detection
fix: detect stale PID files from recycled PIDs
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@@ -99,6 +100,19 @@ func (pm *pidManager) isProcessAlive(pid int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Verify the process is actually hyprvoice and not a recycled PID
|
||||
cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
|
||||
if err != nil {
|
||||
log.Printf("Process %d alive but cannot read cmdline, assuming stale: %v", pid, err)
|
||||
return false
|
||||
}
|
||||
|
||||
exe := string(cmdline)
|
||||
if len(exe) == 0 || !strings.Contains(exe, "hyprvoice") {
|
||||
log.Printf("Process %d is alive but is not hyprvoice (cmdline: %q), stale PID file", pid, exe)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user