]> 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 07:49:01 +0000 (09:49 +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 b3941dd142c8ca88f8707f46ffd438da2ab78206..a57e7a73b4e347af7fc265e7dadba2950e78298b 100644 (file)
@@ -633,12 +633,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;
 }
 
 /*