From: Karel Zak Date: Thu, 24 Sep 2015 10:46:21 +0000 (+0200) Subject: zramctl: fix lists of the all devices X-Git-Tag: v2.28-rc1~335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ceb4077af59a32cdfde954a84c1dd7c0b5b84ed;p=thirdparty%2Futil-linux.git zramctl: fix lists of the all devices The command zramctl lists the same stat info for all devices (DATA COMPR TOTAL). Reported-by: Oliver Freyermuth Signed-off-by: Karel Zak --- diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index 30134338fc..8d60b6cccf 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -35,6 +35,7 @@ #include "optutils.h" #include "ismounted.h" #include "strv.h" +#include "path.h" /*#define CONFIG_ZRAM_DEBUG*/ @@ -145,6 +146,15 @@ static int column_name_to_id(const char *name, size_t namesz) return -1; } +static void zram_reset_stat(struct zram *z) +{ + if (z) { + strv_free(z->mm_stat); + z->mm_stat = NULL; + z->mm_stat_probed = 0; + } +} + static void zram_set_devname(struct zram *z, const char *devname, size_t n) { assert(z); @@ -158,6 +168,7 @@ static void zram_set_devname(struct zram *z, const char *devname, size_t n) DBG(fprintf(stderr, "set devname: %s", z->devname)); sysfs_deinit(&z->sysfs); + zram_reset_stat(z); } static struct zram *new_zram(const char *devname) @@ -176,8 +187,7 @@ static void free_zram(struct zram *z) return; DBG(fprintf(stderr, "free: %p", z)); sysfs_deinit(&z->sysfs); - - strv_free(z->mm_stat); + zram_reset_stat(z); free(z); } @@ -271,7 +281,6 @@ static struct zram *find_free_zram(void) return z; } -#include "path.h" static char *get_mm_stat(struct zram *z, size_t idx, int bytes) {