]> granicus.if.org Git - procps-ng/commitdiff
free: better error message if meminfo not available
authorCraig Small <csmall@dropbear.xyz>
Tue, 31 May 2022 11:10:18 +0000 (21:10 +1000)
committerCraig Small <csmall@dropbear.xyz>
Tue, 31 May 2022 11:10:18 +0000 (21:10 +1000)
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>
free.c

diff --git a/free.c b/free.c
index 94943e8884ecf61f15d1d2d11c4d72f075073db7..75cc751059f3b2c78f97032e89114f547372c621 100644 (file)
--- a/free.c
+++ b/free.c
@@ -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