From: Michal Suchanek Date: Mon, 4 Nov 2019 20:23:15 +0000 (+0100) Subject: libblkid: open device in nonblock mode. X-Git-Tag: v2.35-rc1~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39f5af25982d8b0244000e92a9d0e0e6557d0e17;p=thirdparty%2Futil-linux.git libblkid: open device in nonblock mode. 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 Signed-off-by: Karel Zak --- diff --git a/libblkid/src/evaluate.c b/libblkid/src/evaluate.c index 51e5b058db..8ba8bd5f37 100644 --- a/libblkid/src/evaluate.c +++ b/libblkid/src/evaluate.c @@ -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; diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 790168c16c..f6dd5573d5 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -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; diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c index a78c9f8f2a..4bda3fd40c 100644 --- a/libblkid/src/verify.c +++ b/libblkid/src/verify.c @@ -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, diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index f2583d2b88..0df9f6b6f2 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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; diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index be728279bd..313ddc36e5 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -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;