When using 'procstat binary' to identify whether running code matches the on-disk version, I get the following behaviour: --- $ procstat binary $$ PID COMM OSREL PATH 38822 bash 1500068 /usr/local/bin/bash $ sudo pkg upgrade -qy bash $ procstat binary $$ PID COMM OSREL PATH procstat: sysctl: kern.proc.pathname: 38822: No such file or directory $ echo $? 0 --- I would expect the exit code to be 1, as it would be if the given PID did not exist: --- $ procstat binary 1234 procstat: sysctl(kern.proc): No such process procstat: procstat_getprocs() $ echo $? 1 --- Am I wrong in assuming this can be considered a bug?
I am not sure what should be an exit value from the 'binary' subcommand. OTOH I think that inability to get the path should not abruptly drop the pid from the output: e.g. we could still read the OSREL. https://reviews.freebsd.org/D57493
> Am I wrong in assuming this can be considered a bug? I'd say the behaviour prior to kib's patch in D57493 is indeed a bug: the program failed but did not return an error code. With the change exit probably should be 0: `procstat binary` does report details about the binary, and that the path is not available.
(In reply to Ed Maste from comment #2) Thanks, I had not had time to see/comment on the review. I'm relying on the (old) behaviour in order to detect whether a running process matches the on-disk binary. With this change, can I still do so (i.e. if the binary is `-`)? Is there a better way to achieve what I am after, preferably something that gives a non-zero exit code if the two don't match?
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9f378397ee89044a4faec522916b50f0a164d62e commit 9f378397ee89044a4faec522916b50f0a164d62e Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-06-07 07:28:29 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-06-08 20:14:20 +0000 procstat binary: do not skip pid if either path or osrel sysctls failed PR: 295893 Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D57493 usr.bin/procstat/procstat_bin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=b7280eba6324c203b5aeb87827ffcf7e9da7e467 commit b7280eba6324c203b5aeb87827ffcf7e9da7e467 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-06-07 07:28:29 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-06-13 00:58:38 +0000 procstat binary: do not skip pid if either path or osrel sysctls failed PR: 295893 (cherry picked from commit 9f378397ee89044a4faec522916b50f0a164d62e) usr.bin/procstat/procstat_bin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)