Thanks for the suggestions. I made a new patch reading from /proc/self/mountinfo as suggested by you. In addition, no code is taken from HAL so there is no license issue now. Please review the patch attached to this mail.
On Sat, Feb 26, 2011 at 12:12 AM, Kay Sievers <kay.siev...@vrfy.org> wrote: > On Fri, Feb 25, 2011 at 14:47, PCMan <pcman...@gmail.com> wrote: >> I made a small patch against the latest udisks in git after hacking HAL >> daemon >> and it works. Please review the patch. Thanks a lot. >> >> https://bugs.freedesktop.org/attachment.cgi?id=43798&action=edit > > mtab is officially dead now, even in mount(8). Please always use > /proc/self/mountinfo, it has the major/minor in there, which is a far > more reliable match than the device file name. Example is here: > http://git.kernel.org/?p=linux/hotplug/udev.git;a=blob;f=extras/cdrom_id/cdrom_id.c;h=4a58a49030231f854be8ce63e6b8d700b5f1b832;hb=HEAD#l118 > > HAL was also GPL just like udisks, there is need to get into trouble > with other licences added to the udisks code, especially not for 3 > lines getmntent() parsing. :) > > Tanks, > Kay >
From 8345b59a168f464ee7d488ec0dc25b0203fa2e1f Mon Sep 17 00:00:00 2001 From: Hong Jen Yee (PCMan) <pcman...@gmail.com> 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
_______________________________________________ devkit-devel mailing list devkit-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/devkit-devel