util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blkid: open device in nonblock mode.
@ 2019-11-04 20:23 Michal Suchanek
  2019-11-05 11:41 ` Karel Zak
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Michal Suchanek @ 2019-11-04 20:23 UTC (permalink / raw)
  To: util-linux; +Cc: Michal Suchanek

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.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 libblkid/src/verify.c | 2 +-
 misc-utils/blkid.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c
index a78c9f8f2aa4..4bda3fd40cee 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 f2583d2b883f..0df9f6b6f29e 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;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-01-08  8:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 20:23 [PATCH] blkid: open device in nonblock mode Michal Suchanek
2019-11-05 11:41 ` Karel Zak
2019-11-05 17:13   ` Michal Suchánek
2019-11-06  8:02     ` Michal Suchánek
2019-11-06  8:48       ` Karel Zak
2019-11-06  9:45         ` Michal Suchánek
2019-11-12  8:27         ` Anatoly Pugachev
2019-11-12  8:58           ` Karel Zak
2019-11-06  9:00 ` Karel Zak
2020-01-07 16:04 ` Karel Zak
2020-01-07 16:19   ` Michal Suchánek
2020-01-08  8:25     ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).