The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e79866ddf1c2147890226830838dcca5174c18e1

commit e79866ddf1c2147890226830838dcca5174c18e1
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2022-04-07 18:27:12 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2022-04-09 21:47:50 +0000

    procstat(1): add ability to specify subcommands not requiring pid lists
    
    Add PS_MODE_NO_KINFO_PROC cmd modifier that indicates that neither
    process list should be queried from the kernel, nor list of pids or `-a`
    switch provided on the command line to filter the output.
    
    This is intended for use by commands that query information not
    neccessary attributed to specific process.
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D34834
---
 usr.bin/procstat/procstat.c | 9 ++++++++-
 usr.bin/procstat/procstat.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index bb3b9e9de5a8..220f63f2703e 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -449,7 +449,8 @@ main(int argc, char *argv[])
        }
 
        /* Must specify either the -a flag or a list of pids. */
-       if (!(aflag == 1 && argc == 0) && !(aflag == 0 && argc > 0))
+       if (!(aflag == 1 && argc == 0) && !(aflag == 0 && argc > 0) &&
+           (cmd->cmp & PS_MODE_NO_KINFO_PROC) == 0)
                usage(cmd);
 
        if (memf != NULL)
@@ -465,6 +466,11 @@ main(int argc, char *argv[])
                xo_open_container(progname);
                xo_open_container(xocontainer);
 
+               if ((cmd->cmp & PS_MODE_NO_KINFO_PROC) != 0) {
+                       cmd->cmd(prstat, NULL);
+                       goto iter;
+               }
+
                if (aflag) {
                        p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt);
                        if (p == NULL)
@@ -520,6 +526,7 @@ main(int argc, char *argv[])
                        }
                }
 
+iter:
                xo_close_container(xocontainer);
                xo_close_container(progname);
                xo_finish();
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index 5a0bc193ab45..5b54d4c4ff2f 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -44,6 +44,7 @@ enum {
        PS_OPT_SIGNUM           = 0x08,
        PS_OPT_VERBOSE          = 0x10,
        PS_MODE_COMPAT          = 0x20,
+       PS_MODE_NO_KINFO_PROC   = 0x40,
 };
 
 #define PS_SUBCOMMAND_OPTS                     \

Reply via email to