First cut at subset=pid proc mount handling

The procfs mount option subset=pid only shows the processes, not things
such as /proc/stat etc.

For certain programs, this should mean they still work, but have reduced
functionality. This is the first cut at some of them.

pgrep - Removed always loading uptime which we never used anyway. The
program now works fine unless we use --older. Add note in man page
stating it will silently fail.

ps - Load boot time and memory total only when required instead of
always. Changed the error messages to something the user actually
cares about "can't get system boot time" vs "create a structure".
Works for most fields except starts and percent memory.

uptime - Give more useful error messages if uptime not available.

vmstat - move header generation after testing for required proc
files, makes the default output more consistent with the rest
of the options.

References:
 procps-ng/procps#227
 https://www.kernel.org/doc/html/latest/filesystems/proc.html#chapter-4-configuring-procfs
 6814ef2d99

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Craig Small
2021-12-16 20:36:00 +11:00
parent dae897b54d
commit bcb837b8c7
5 changed files with 40 additions and 29 deletions

View File

@@ -585,13 +585,9 @@ static struct el * select_procs (int *num)
char *cmdoutput = xmalloc(cmdlen);
char *task_cmdline;
enum pids_fetch_type which;
double uptime_secs;
preg = do_regcomp();
if (procps_uptime(&uptime_secs, NULL) < 0)
xerrx(EXIT_FAILURE, "uptime");
if (opt_newest) saved_start_time = 0ULL;
else saved_start_time = ~0ULL;