]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
zramctl: fail status printout when device does not exist
authorKarel Zak <kzak@redhat.com>
Mon, 11 Aug 2014 12:26:20 +0000 (14:26 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Aug 2014 12:26:20 +0000 (14:26 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/zramctl.c

index 241e6fb0fde858ab11f98e53dc792528be8aec52..bdab4ad5928d3b347335d42d0420f52d558f0318 100644 (file)
@@ -167,8 +167,11 @@ static inline int zram_exist(struct zram *z)
 {
        assert(z);
 
-       if (zram_get_sysfs(z) == NULL)
+       errno = 0;
+       if (zram_get_sysfs(z) == NULL) {
+               errno = ENODEV;
                return 0;
+       }
 
        DBG(fprintf(stderr, "%s exists", z->devname));
        return 1;
@@ -511,8 +514,11 @@ int main(int argc, char **argv)
                        columns[ncolumns++] = COL_STREAMS;
                        columns[ncolumns++] = COL_MOUNTPOINT;
                }
-               if (optind < argc)
+               if (optind < argc) {
                        zram = new_zram(argv[optind++]);
+                       if (!zram_exist(zram))
+                               err(EXIT_FAILURE, zram->devname);
+               }
                status(zram);
                free_zram(zram);
                break;
@@ -521,7 +527,8 @@ int main(int argc, char **argv)
                        errx(EXIT_FAILURE, _("no device specified"));
                while (optind < argc) {
                        zram = new_zram(argv[optind]);
-                       if (zram_set_u64parm(zram, "reset", 1)) {
+                       if (!zram_exist(zram)
+                           || zram_set_u64parm(zram, "reset", 1)) {
                                warn(_("%s: failed to reset"), zram->devname);
                                rc = 1;
                        }
@@ -543,8 +550,11 @@ int main(int argc, char **argv)
                                errx(EXIT_FAILURE, _("no free zram device found"));
                } else if (optind == argc)
                        errx(EXIT_FAILURE, _("no device specified"));
-               else
+               else {
                        zram = new_zram(argv[optind]);
+                       if (!zram_exist(zram))
+                               err(EXIT_FAILURE, zram->devname);
+               }
 
                if (zram_set_u64parm(zram, "reset", 1))
                        err(EXIT_FAILURE, _("%s: failed to reset"), zram->devname);