summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Suchanek <msuchanek@suse.de>2019-10-20 12:12:20 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-10-24 00:09:18 +0200
commit14cd12b3d50f21cb9be7e27785142c6c321fac39 (patch)
treef3c570f44d9746792d7d754f1e58fd22245bb894
parent69ec2fdd9c7a12c37bb02f7ec7690b6535502dd8 (diff)
downloadsystemd-14cd12b3d50f21cb9be7e27785142c6c321fac39.tar.gz
udev/cdrom_id: Do not open CD-rom in exclusive mode.
When you have a CD automunt solution that talks directly to the kernel independently of udev it races with cdrom_id for exclusive access to the device failing unpredictably. The whole is_mounted function in cdrom_id is broken: there is no saying what happens between calling is_mounted and opening the device. Hence assume that the device can be mounted asynchronously at any time, do not use exclusive access, and do away with is_mouted. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
-rw-r--r--src/udev/cdrom_id/cdrom_id.c24
1 files changed, 1 insertions, 23 deletions
diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index 75afe4e7c9..13b947beb1 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -85,28 +85,6 @@ static unsigned long long int cd_media_session_last_offset;
#define ASC(errcode) (((errcode) >> 8) & 0xFF)
#define ASCQ(errcode) ((errcode) & 0xFF)
-static bool is_mounted(const char *device) {
- struct stat statbuf;
- FILE *fp;
- int maj, min;
- bool mounted = false;
-
- if (stat(device, &statbuf) < 0)
- return false;
-
- fp = fopen("/proc/self/mountinfo", "re");
- if (!fp)
- return false;
- while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
- if (makedev(maj, min) == statbuf.st_rdev) {
- mounted = true;
- break;
- }
- }
- fclose(fp);
- return mounted;
-}
-
static void info_scsi_cmd_err(const char *cmd, int err) {
if (err == -1)
log_debug("%s failed", cmd);
@@ -874,7 +852,7 @@ int main(int argc, char *argv[]) {
for (cnt = 20; cnt > 0; cnt--) {
struct timespec duration;
- fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|(is_mounted(node) ? 0 : O_EXCL));
+ fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
if (fd >= 0 || errno != EBUSY)
break;
duration.tv_sec = 0;