mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-11-10 14:44:04 +08:00
processExists used kill(pid, 0) and treated any error as "gone", but that syscall returns EPERM when the target PID exists but belongs to a user the caller can't signal (e.g. ntfy running as a regular user waiting on a root-owned restic process). The wait loop then exited immediately with "process with PID ... not running" even though the process was very much alive. Treat EPERM as "exists" and only ESRCH as "gone". The loop stays correct: EPERM while the target is alive, ESRCH once it exits. Also fix the pidof example in docs/subscribe/cli.md: plain `pidof X` returns space-separated PIDs when multiple matches exist, which breaks --wait-pid's single-int argument. Use `pidof -s` (single-shot) so the example works even with multiple matching processes.
17 lines
273 B
Go
17 lines
273 B
Go
//go:build darwin || linux || dragonfly || freebsd || netbsd || openbsd
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"syscall"
|
|
)
|
|
|
|
func processExists(pid int) bool {
|
|
err := syscall.Kill(pid, syscall.Signal(0))
|
|
if err == nil {
|
|
return true
|
|
}
|
|
return errors.Is(err, syscall.EPERM)
|
|
}
|