File util-linux-libblkid-cdrom-autoclose-1.patch of Package util-linux.12160
From 39f5af25982d8b0244000e92a9d0e0e6557d0e17 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Mon, 4 Nov 2019 21:23:15 +0100
Subject: [PATCH] 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 <msuchanek@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
libblkid/src/evaluate.c | 2 +-
libblkid/src/probe.c | 2 +-
libblkid/src/verify.c | 2 +-
misc-utils/blkid.c | 2 +-
misc-utils/wipefs.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
Index: util-linux-2.28/libblkid/src/evaluate.c
===================================================================
--- util-linux-2.28.orig/libblkid/src/evaluate.c
+++ util-linux-2.28/libblkid/src/evaluate.c
@@ -70,7 +70,7 @@ static int verify_tag(const char *devnam
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: util-linux-2.28/libblkid/src/probe.c
===================================================================
--- util-linux-2.28.orig/libblkid/src/probe.c
+++ util-linux-2.28/libblkid/src/probe.c
@@ -217,7 +217,7 @@ blkid_probe blkid_new_probe_from_filenam
if (!filename)
return NULL;
- fd = open(filename, O_RDONLY|O_CLOEXEC);
+ fd = open(filename, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return NULL;
Index: util-linux-2.28/libblkid/src/verify.c
===================================================================
--- util-linux-2.28.orig/libblkid/src/verify.c
+++ util-linux-2.28/libblkid/src/verify.c
@@ -126,7 +126,7 @@ blkid_dev blkid_verify(blkid_cache cache
}
}
- 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: util-linux-2.28/misc-utils/blkid.c
===================================================================
--- util-linux-2.28.orig/misc-utils/blkid.c
+++ util-linux-2.28/misc-utils/blkid.c
@@ -484,7 +484,7 @@ static int lowprobe_device(blkid_probe p
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) {
fprintf(stderr, "error: %s: %m\n", devname);
return BLKID_EXIT_NOTFOUND;
Index: util-linux-2.28/misc-utils/wipefs.c
===================================================================
--- util-linux-2.28.orig/misc-utils/wipefs.c
+++ util-linux-2.28/misc-utils/wipefs.c
@@ -236,7 +236,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;