]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
zramctl: make mm_stat parser more robust
authorKarel Zak <kzak@redhat.com>
Thu, 30 Mar 2017 10:10:01 +0000 (12:10 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 30 Mar 2017 10:10:01 +0000 (12:10 +0200)
Let's fallback to attribute files if mm_stat file is incomplete. It
should not happen, but I have seen RHEL7 kernel where is no
num_migrated/pages_compacted attribute...

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/zramctl.c

index 29bdb851895c1bb9861000f1818f266a6243d309..b5fc08edf2e5eefa5a350294d538abf016be2a18 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);