]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: print more usable error message on failed -f
authorKarel Zak <kzak@redhat.com>
Wed, 3 Jun 2015 10:05:09 +0000 (12:05 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Jun 2015 10:05:09 +0000 (12:05 +0200)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1215370
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index c2bbd0d1482d1cc20a3f04c854796711b60d2fef..9201782ad64069e895d9e3cf73ce2385654ad9a2 100644 (file)
@@ -25,6 +25,7 @@
 #include "optutils.h"
 #include "xalloc.h"
 #include "canonicalize.h"
+#include "pathnames.h"
 
 enum {
        A_CREATE = 1,           /* setup a new device */
@@ -697,9 +698,17 @@ int main(int argc, char **argv)
                break;
        case A_FIND_FREE:
                res = loopcxt_find_unused(&lc);
-               if (res)
+               if (res) {
+                       int errsv = errno;
+
+                       if (access(_PATH_DEV_LOOPCTL, F_OK) == 0 &&
+                           access(_PATH_DEV_LOOPCTL, W_OK) != 0)
+                               ;
+                       else
+                               errno = errsv;
+
                        warn(_("cannot find an unused loop device"));
-               else
+               else
                        printf("%s\n", loopcxt_get_device(&lc));
                break;
        case A_SHOW: