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.28.2~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce7d7d2ff9a3d3d2f07dc578c2bc15034e7f44ea;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 26c183e8d6..7a69cd9c7e 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -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; } /*