Files
ntfy/cmd/publish_unix.go
T
Benedikt Koeppel a0eb1697f0 Fix --wait-pid false-negative for cross-user processes and pidof docs
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.
2026-04-20 10:42:34 +02:00

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)
}