]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: open device in nonblock mode.
authorMichal Suchanek <msuchanek@suse.de>
Mon, 4 Nov 2019 20:23:15 +0000 (21:23 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Nov 2019 08:55:49 +0000 (09:55 +0100)
When autoclose is set (kernel default but many distributions reverse the
setting) opening a CD-rom device causes the tray to close.

The function of blkid is to report the current state of the device and
not to change it. Hence it should use O_NONBLOCK when opening the
device to avoid closing a CD-rom tray.

blkid is used liberally in scripts so it can potentially interfere with
the user operating the CD-rom hardware.

[kzak@redhat.com: add O_NONBLOCK also to:
                  - wipefs
                  - blkid_new_probe_from_filename()
                  - blkid_evaluate_tag()]

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/evaluate.c
libblkid/src/probe.c
libblkid/src/verify.c
misc-utils/blkid.c
misc-utils/wipefs.c

index 51e5b058db1d0c3e1f4a2f665d4520eeb588d6e3..8ba8bd5f372b3a87c96af6634388caa4aa544b87 100644 (file)
@@ -70,7 +70,7 @@ static int verify_tag(const char *devname, const char *name, const char *value)
        blkid_probe_enable_partitions(pr, TRUE);
        blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
 
-       fd = open(devname, O_RDONLY|O_CLOEXEC);
+       fd = open(devname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
        if (fd < 0) {
                errsv = errno;
                goto done;
index 790168c16cbe248154150e89627296a5899f14fe..f6dd5573d5dd6ccef2fbf7042b12c30ea1509c43 100644 (file)
@@ -203,7 +203,7 @@ blkid_probe blkid_new_probe_from_filename(const char *filename)
        int fd;
        blkid_probe pr = NULL;
 
-       fd = open(filename, O_RDONLY|O_CLOEXEC);
+       fd = open(filename, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
        if (fd < 0)
                return NULL;
 
index a78c9f8f2aa4a13ef26f6988797d0206255f5a24..4bda3fd40ceefe3a3063b88407625a1a526a1bd9 100644 (file)
@@ -126,7 +126,7 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
                }
        }
 
-       fd = open(dev->bid_name, O_RDONLY|O_CLOEXEC);
+       fd = open(dev->bid_name, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
        if (fd < 0) {
                DBG(PROBE, ul_debug("blkid_verify: error %m (%d) while "
                                        "opening %s", errno,
index f2583d2b883f4270204dec4fc8943e91676fd572..0df9f6b6f29e986618d471e5dbdf1cf82d631179 100644 (file)
@@ -499,7 +499,7 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
        int rc = 0;
        static int first = 1;
 
-       fd = open(devname, O_RDONLY|O_CLOEXEC);
+       fd = open(devname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
        if (fd < 0) {
                warn(_("error: %s"), devname);
                return BLKID_EXIT_NOTFOUND;
index be728279bd41f862923a73fcbca2dda536756800..313ddc36e528e570dea595cab313e35025f72100 100644 (file)
@@ -386,7 +386,7 @@ new_probe(const char *devname, int mode)
                return NULL;
 
        if (mode) {
-               int fd = open(devname, mode);
+               int fd = open(devname, mode | O_NONBLOCK);
                if (fd < 0)
                        goto error;