All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Suchanek <msuchanek@suse.de>
To: util-linux@vger.kernel.org
Cc: Michal Suchanek <msuchanek@suse.de>
Subject: [PATCH] blkid: open device in nonblock mode.
Date: Mon,  4 Nov 2019 21:23:15 +0100	[thread overview]
Message-ID: <20191104202315.4879-1-msuchanek@suse.de> (raw)

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


             reply	other threads:[~2019-11-04 20:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 20:23 Michal Suchanek [this message]
2019-11-05 11:41 ` [PATCH] blkid: open device in nonblock mode 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191104202315.4879-1-msuchanek@suse.de \
    --to=msuchanek@suse.de \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.