Bug 295893 - "procstat binary <pid>" returns 0 despite file not found after replacing binary
Summary: "procstat binary <pid>" returns 0 despite file not found after replacing binary
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-06-06 13:15 UTC by Eirik Oeverby
Modified: 2026-06-13 17:40 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eirik Oeverby 2026-06-06 13:15:38 UTC
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?
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-07 07:33:08 UTC
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
Comment 2 Ed Maste freebsd_committer freebsd_triage 2026-06-08 18:40:48 UTC
> 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.
Comment 3 Eirik Oeverby 2026-06-08 19:05:31 UTC
(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?
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-06-08 20:15:30 UTC
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(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-06-13 01:04:42 UTC
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(-)