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(-) diff --git a/src/poller.c b/src/poller.c index 9517b5d..837f516 100644 --- a/src/poller.c +++ b/src/poller.c @@ -105,6 +105,41 @@ static gchar **poller_devices_to_poll = NULL; 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_poll_device (const gchar *device_file) { @@ -126,6 +161,22 @@ poller_poll_device (const gchar *device_file) * - use O_EXCL to avoid interferring with cd burning software / audio playback / etc */ fd = open (device_file, 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) { close (fd); -- 1.7.4.1