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
This commit is contained in:
Konstantin Belousov 2022-04-07 21:27:12 +03:00
parent 50d3c72558
commit e79866ddf1
2 changed files with 9 additions and 1 deletions

View File

@ -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();

View File

@ -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 \