From: Tobias Stoeckmann Date: Tue, 30 Aug 2016 19:00:38 +0000 (+0200) Subject: lib/loopdev: Set errno in is_loopdev on error X-Git-Tag: v2.29-rc1~89 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb129d9cc4a2ae39ba2b678bc511ff81d5023850;p=thirdparty%2Futil-linux.git lib/loopdev: Set errno in is_loopdev on error 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 --- diff --git a/lib/loopdev.c b/lib/loopdev.c index b3941dd142..a57e7a73b4 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -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; } /*