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:
12
uptime.c
12
uptime.c
@@ -44,7 +44,7 @@ static void print_uptime_since()
|
||||
|
||||
/* Get the uptime and calculate when that was */
|
||||
if (procps_uptime(&uptime_secs, &idle_secs) < 0)
|
||||
xerrx(EXIT_FAILURE, "uptime");
|
||||
xerr(EXIT_FAILURE, _("Cannot get system uptime"));
|
||||
up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
|
||||
|
||||
/* Show this */
|
||||
@@ -72,6 +72,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c, p = 0;
|
||||
char *uptime_str;
|
||||
|
||||
static const struct option longopts[] = {
|
||||
{"pretty", no_argument, NULL, 'p'},
|
||||
@@ -110,8 +111,13 @@ int main(int argc, char **argv)
|
||||
usage(stderr);
|
||||
|
||||
if (p)
|
||||
printf("%s\n", procps_uptime_sprint_short());
|
||||
uptime_str = procps_uptime_sprint_short();
|
||||
else
|
||||
printf("%s\n", procps_uptime_sprint());
|
||||
uptime_str = procps_uptime_sprint();
|
||||
|
||||
if (!uptime_str || uptime_str[0] == '\0')
|
||||
xerr(EXIT_FAILURE, _("Cannot get system uptime"));
|
||||
|
||||
printf("%s\n", uptime_str);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user