From 8345b59a168f464ee7d488ec0dc25b0203fa2e1f Mon Sep 17 00:00:00 2001 From: Hong Jen Yee (PCMan) Date: Sat, 26 Feb 2011 16:43:53 +0800 Subject: [PATCH] Fix #34710 - [udisks] CD-ROM polling failed due to O_EXCL flag (poller.c). --- src/poller.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) Index: udisks-1.0.2/src/poller.c =================================================================== --- udisks-1.0.2.orig/src/poller.c 2011-03-11 11:57:48.000000000 +0100 +++ udisks-1.0.2/src/poller.c 2011-03-11 11:58:28.000000000 +0100 @@ -119,6 +119,41 @@ static guint poller_timeout_id = 0; + +/* Check if a filesystem on a special device file is mounted */ +/* Reference: [linux/hotplug/udev.git]/extras/cdrom_id/cdrom_id.c */ +static gboolean +is_mounted (const gchar *device_file) +{ + struct stat statbuf; + int major, minor; + FILE* f; + gboolean ret; + gchar line[100]; + + if (stat (device_file, &statbuf) < 0) + return FALSE; + + ret = FALSE; + f = fopen ("/proc/self/mountinfo", "r"); + if (f) + { + while (fgets(line, 100, f)) + { + if (sscanf(line, "%*s %*s %d:%d", &major, &minor) == 2) + { + if (makedev(major, minor) == statbuf.st_rdev) + { + ret = TRUE; + break; + } + } + } + fclose(f); + } + return ret; +} + static void poller_check_ide_cdrom (int fd, PollerDevice *device) { @@ -193,6 +228,22 @@ * - use O_EXCL to avoid interferring with cd burning software / audio playback / etc */ fd = open (device->dev_path, O_RDONLY | O_NONBLOCK | O_EXCL); + if (fd == -1 && errno == EBUSY) + { + /* From hal/hald/linux/addons/addon-storage.c: */ + /* this means the disc is mounted or some other app, + * like a cd burner, has already opened O_EXCL */ + + /* HOWEVER, when starting hald, a disc may be + * mounted; so check /etc/mtab to see if it + * actually is mounted. If it is we retry to open + * without O_EXCL + */ + if (is_mounted (device_file)) + { + fd = open (device_file, O_RDONLY | O_NONBLOCK); + } + } if (fd != -1) { if (device->is_ide_cdrom)