]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/loopdev: check for /sys
authorKarel Zak <kzak@redhat.com>
Wed, 17 Oct 2012 09:43:39 +0000 (11:43 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 31 Oct 2012 12:52:45 +0000 (13:52 +0100)
The current loopdev code prefers /sys to get information about
loop devices. The old methods like scan /dev are fallback solution
only. Unfortunately, the code does not check if /sys is mounted.

Addresses: http://blog.flameeyes.eu/2012/10/sophistication-can-be-bad
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev.c

index 0e6033a255f132270fae36fd3cf6a69026326f13..f62af83c289ac33e5600a37bc6ee88403ddff62c 100644 (file)
@@ -167,6 +167,12 @@ int loopcxt_init(struct loopdev_cxt *lc, int flags)
        if (rc)
                return rc;
 
+       if (stat(_PATH_SYS_BLOCK, &st) || !S_ISDIR(st.st_mode)) {
+               lc->flags |= LOOPDEV_FL_NOSYSFS;
+               lc->flags &= ~LOOPDEV_FL_NOIOCTL;
+               DBG(lc, loopdev_debug("init: disable /sys usage"));
+       }
+
        if (!(lc->flags & LOOPDEV_FL_NOSYSFS) &&
            get_linux_version() >= KERNEL_VERSION(2,6,37)) {
                /*