mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-15 07:35:49 -06:00
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.
This commit is contained in:
parent
6cfadf9681
commit
a0eb1697f0
2 changed files with 9 additions and 3 deletions
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
package cmd
|
||||
|
||||
import "syscall"
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func processExists(pid int) bool {
|
||||
err := syscall.Kill(pid, syscall.Signal(0))
|
||||
return err == nil
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
return errors.Is(err, syscall.EPERM)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ Or, if you already started the long-running process and want to wait for it usin
|
|||
|
||||
=== "Using a `pidof`"
|
||||
```
|
||||
$ ntfy pub --wait-pid $(pidof rsync) mytopic | jq .
|
||||
$ ntfy pub --wait-pid $(pidof -s rsync) mytopic | jq .
|
||||
{
|
||||
"id": "orM6hJKNYkWb",
|
||||
"time": 1655825827,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue