summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorKarel Zak2015-06-03 12:05:09 +0200
committerKarel Zak2015-06-03 12:05:09 +0200
commit362f5d203581e895005b91383ea7b1affafd8eba (patch)
treebc7460acff032e032c4f4c49f23a0c15d76b0d6b /sys-utils/losetup.c
parentlibmount: do not call umount helper on --fake (diff)
downloadkernel-qcow2-util-linux-362f5d203581e895005b91383ea7b1affafd8eba.tar.gz
kernel-qcow2-util-linux-362f5d203581e895005b91383ea7b1affafd8eba.tar.xz
kernel-qcow2-util-linux-362f5d203581e895005b91383ea7b1affafd8eba.zip
losetup: print more usable error message on failed -f
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1215370 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index c2bbd0d14..9201782ad 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -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: