]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/zramctl.c
misc: consolidate smartcols error messages
[thirdparty/util-linux.git] / sys-utils / zramctl.c
index 853401caf21af4596101bf67263d28f06c2c85d0..4ae4742dd200d579df8b871299a98dbe75ad7f43 100644 (file)
@@ -359,8 +359,12 @@ static char *get_mm_stat(struct zram *z, size_t idx, int bytes)
                str = sysfs_strdup(sysfs, "mm_stat");
                if (str) {
                        z->mm_stat = strv_split(str, " ");
-                       if (strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names))
-                               errx(EXIT_FAILURE, _("Failed to parse mm_stat"));
+
+                       /* make sure kernel provides mm_stat as expected */
+                       if (strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names)) {
+                               strv_free(z->mm_stat);
+                               z->mm_stat = NULL;
+                       }
                }
                z->mm_stat_probed = 1;
                free(str);
@@ -402,7 +406,7 @@ static void fill_table_row(struct libscols_table *tb, struct zram *z)
 
        ln = scols_table_new_line(tb, NULL);
        if (!ln)
-               err(EXIT_FAILURE, _("failed to initialize output line"));
+               err(EXIT_FAILURE, _("failed to allocate output line"));
 
        for (i = 0; i < (size_t) ncolumns; i++) {
                char *str = NULL;
@@ -467,8 +471,8 @@ static void fill_table_row(struct libscols_table *tb, struct zram *z)
                        str = get_mm_stat(z, MM_NUM_MIGRATED, inbytes);
                        break;
                }
-               if (str)
-                       scols_line_refer_data(ln, i, str);
+               if (str && scols_line_refer_data(ln, i, str))
+                       err(EXIT_FAILURE, _("failed to add output data"))
        }
 }
 
@@ -481,7 +485,7 @@ static void status(struct zram *z)
 
        tb = scols_new_table();
        if (!tb)
-               err(EXIT_FAILURE, _("failed to initialize output table"));
+               err(EXIT_FAILURE, _("failed to allocate output table"));
 
        scols_table_enable_raw(tb, raw);
        scols_table_enable_noheadings(tb, no_headings);
@@ -640,7 +644,7 @@ int main(int argc, char **argv)
                case 'h':
                        usage(stdout);
                default:
-                       usage(stderr);
+                       errtryhelp(EXIT_FAILURE);
                }
        }