]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/loopdev: Set errno in is_loopdev on error
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 30 Aug 2016 19:00:38 +0000 (21:00 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 31 Aug 2016 09:08:12 +0000 (11:08 +0200)
The function is_loopdev does not set errno if the supplied string does
not reference a valid loop device. Fix this to avoid an error message
like this one:

  losetup: /: failed to use device: Success

I prefer this one:

  losetup: /: failed to use device: No such device

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/loopdev.c

index 26c183e8d6a5c03505cf6268e32cb7c315f599df..7a69cd9c7e0ec880699b19ad08944c4c934788f9 100644 (file)
@@ -634,12 +634,13 @@ int is_loopdev(const char *device)
 {
        struct stat st;
 
-       if (!device)
-               return 0;
-
-       return (stat(device, &st) == 0 &&
+       if (device && stat(device, &st) == 0 &&
                S_ISBLK(st.st_mode) &&
-               major(st.st_rdev) == LOOPDEV_MAJOR);
+               major(st.st_rdev) == LOOPDEV_MAJOR)
+               return 1;
+
+       errno = ENODEV;
+       return 0;
 }
 
 /*