free: better error message if meminfo not available

When /proc is mounted with subset=pid free just gives the
standard cannot create meminfo structure without any hint why.
free now checks the return value and if it is -ENOENT then it
gives more information about the problem.

References:
 procps-ng/procps#227

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Craig Small 2022-05-31 21:10:18 +10:00
parent 4a183003a0
commit 0ab507fdb1
1 changed files with 10 additions and 4 deletions

14
free.c
View File

@ -205,7 +205,7 @@ static void print_head_col(const char *str)
int main(int argc, char **argv)
{
int c, flags = 0, unit_set = 0;
int c, flags = 0, unit_set = 0, rc = 0;
struct commandline_arguments args;
struct meminfo_info *mem_info = NULL;
@ -360,9 +360,15 @@ int main(int argc, char **argv)
if (optind != argc)
usage(stderr);
if (procps_meminfo_new(&mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to create meminfo structure"));
if ( (rc = procps_meminfo_new(&mem_info)) < 0)
{
if (rc == -ENOENT)
xerrx(EXIT_FAILURE,
_("Memory information file /proc/meminfo does not exist"));
else
xerrx(EXIT_FAILURE,
_("Unable to create meminfo structure"));
}
do {
/* Translation Hint: You can use 9 character words in
* the header, and the words need to be right align to