cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
05ad79
From a7f11e525e9dd5abf844ada0ddd0ae74950e2e40 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Thu, 30 Mar 2017 12:10:01 +0200
05ad79
Subject: [PATCH] zramctl: make mm_stat parser more robust
05ad79
05ad79
Let's fallback to attribute files if mm_stat file is incomplete. It
05ad79
should not happen, but I have seen RHEL7 kernel where is no
05ad79
num_migrated/pages_compacted attribute...
05ad79
05ad79
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1358755
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/2546d54bd8b0ceac75d6d7e6c483479022d97509
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 sys-utils/zramctl.c | 8 ++++++--
05ad79
 1 file changed, 6 insertions(+), 2 deletions(-)
05ad79
05ad79
diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c
05ad79
index 853401c..c3112d6 100644
05ad79
--- a/sys-utils/zramctl.c
05ad79
+++ b/sys-utils/zramctl.c
05ad79
@@ -359,8 +359,12 @@ static char *get_mm_stat(struct zram *z, size_t idx, int bytes)
05ad79
 		str = sysfs_strdup(sysfs, "mm_stat");
05ad79
 		if (str) {
05ad79
 			z->mm_stat = strv_split(str, " ");
05ad79
-			if (strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names))
05ad79
-				errx(EXIT_FAILURE, _("Failed to parse mm_stat"));
05ad79
+
05ad79
+			/* make sure kernel provides mm_stat as expected */
05ad79
+			if (strv_length(z->mm_stat) < ARRAY_SIZE(mm_stat_names)) {
05ad79
+				strv_free(z->mm_stat);
05ad79
+				z->mm_stat = NULL;
05ad79
+			}
05ad79
 		}
05ad79
 		z->mm_stat_probed = 1;
05ad79
 		free(str);
05ad79
-- 
05ad79
2.9.3
05ad79