]> 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, 17 Oct 2012 09:51:10 +0000 (11:51 +0200)
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 a552fb7556e16fc7f67db15783f7b71eb387c069..dc93a69d7e5e64db7bc4b232702f9a5c1046a6e1 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)) {
                /*