Re: UDisks dbus async calls don't work sometimes when a second mainloop exists

2010-06-29 Thread PCMan
Thank you all for the quick reply.
Is there any suggested way to workaround this?
I previously tried to schedule a idle handler and call FilesystemMount
in it instead, and it works. However, this could make things out of
sync.
When my idle handler get called, it's possible that the device was
already removed. Or its properties may already being changed. However
currently I don't find a better way.

Any suggestions?

On Wed, Jun 30, 2010 at 4:46 AM, Will Thompson
 wrote:
> On 29/06/10 21:41, Havoc Pennington wrote:
>>
>> The issue may be that the dbus-glib mainloop source is set to
>> nonrecursive. This is because historically the thread lock on
>> DBusConnection was not recursive so you would deadlock if you tried to
>> dispatch DBusConnection from within an existing dispatch.
>>
>> I'm not sure whether the main loop source is still nonrecursive or
>> whether it needs to be. It may be a relic.
>
> This issue is . I looked
> into it briefly recently, and commented on the bug.
>
> --
> Will
>
___
devkit-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel


[udisks] CD-ROM polling failed due to O_EXCL flag (poller.c)

2011-02-25 Thread PCMan
Hi list,
UDisks failed to perform ForceUnmount when I press the physical eject
button on my CDROM.
So I downloaded udisks source code from git and traced it for a while
and then I found the problem.

Here are the related properties of my device.
--
  device-file: /dev/sr0
  removable:   1
  has media:   1 (detected at Fri Feb 25 19:16:23 2011)
detects change:1
detection by polling:  1  <---  I have no SATA AN, so polling
is performed.
detection inhibitable: 1
detection inhibited:   0  <-- polling of the device is not inhibited.
  is read only:0
  is mounted:  1
  drive:
vendor:HL-DT-ST
model: HL-DT-ST DVDRAM GMA-4082N
revision:  CX08
serial:M0573JA3106
detachable:0
ejectable: 1
media: optical_cd
interface: scsi
-
I tested udisks on a clean system in a clean xsession + terminal
emulator so there shouldn't be other programs interfering with udisks.

In src/poller.c, poller_poll_device() :

  fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);
  if (fd != -1)
  close (fd);

When I inserted a CD, this call to open() succeeded and returned a
valid fd. I enabled POLL_SHOW_DEBUG, and according to the debug
message, the device was polled every 2 seconds as expected.

However, after the device is mounted, either by udisks --mount or by
calling sudo mount myself, open(device_file) always returns -1 here.
Then, I press the physical eject button on my CDROM to get its tray
opened. The polling code should let udisks detect the media removal
and then invokes ForceUnmount, but this is not the case. The call to
open() kept returning -1 every 2 seconds and udisks didn't detect the
media change at all. Checking errno, "Device is busy" is reported.

Then I remove the O_EXCL flag and perform the whole test again. This
time, after the CD is removed by pressing physical eject button, the
open() call succeeded and returned a valid fd. Then, udisks detects
the media change and gracefully perform ForceUnmount for it.
Everything works fine as expected.

In addition, when "Device is busy", I tried fuser and lsof, but none
of them demonstrates other process using the device. However, if I
unmount the device either by calling sudo umount or udisks --unmount,
this error is gone and open() can return a valid fd. Then everything
works.

Removing O_EXCL from this open() call seems to fix the issue, but this
of course is not the correct way to fix it.

Another interesting thing I found is, if I call udisks
--poll-for-media change manually after forced removal of CD with
physical eject button, then udisks can correctly detect media change.
The polling helper process uses the same source code as in poller.c,
but poller.c doesn't work and I don't know why.

Please, if any udisks developer is reading this, test this with a
CDROM without SATA AN. It's 100% reproducible here. The poller is
invoked every 2 seconds correctly, but the polling does not work. One
of my friend have similar problems that after physical eject udisks
didn't detect the change.

I already filed a bug report for this:# 34710.

Thanks a lot.
___
devkit-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel


Re: [udisks] CD-ROM polling failed due to O_EXCL flag (poller.c)

2011-02-25 Thread PCMan
Please see similar source code from the deprecated HAL.:
hal/hald/linux/addons/addon-storage.c:
While UDIsks add O_EXCL unconditionally, HAL tries O_EXCL first, and
if the device is busy, in some cases it does it without that flag.

static gboolean
poll_for_media_force (void)
{
int fd;
int got_media;
int old_media_status;

got_media = FALSE;

old_media_status = media_status;
if (is_cdrom) {
int drive;

fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);

if (fd < 0 && errno == EBUSY) {
/* 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)) {
if (!is_locked_via_o_excl) {
is_locked_via_o_excl = TRUE;
update_proc_title ();
} else {
is_locked_via_o_excl = TRUE;
}
goto skip_check;
}

fd = open (device_file, O_RDONLY | O_NONBLOCK);
}

___
devkit-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel


Re: [udisks] CD-ROM polling failed due to O_EXCL flag (poller.c)

2011-02-25 Thread PCMan
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
From d963e58dc5393d770191c2265512f41f9d85d406 Mon Sep 17 00:00:00 2001
From: Hong Jen Yee (PCMan) 
Date: Fri, 25 Feb 2011 21:39:36 +0800
Subject: [PATCH] Fix #34710 - [udisks] CD-ROM polling failed due to O_EXCL flag (poller.c).

---
 src/poller.c |   54 ++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/poller.c b/src/poller.c
index 9517b5d..01002c5 100644
--- a/src/poller.c
+++ b/src/poller.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "poller.h"
 #include "device.h"
@@ -105,6 +106,43 @@ static gchar **poller_devices_to_poll = NULL;
 
 static guint poller_timeout_id = 0;
 
+
+/** Check if a filesystem on a special device file is mounted
+ *
+ *  @param  device_file Special device file, e.g. /dev/cdrom
+ *  @return TRUE iff there is a filesystem system mounted
+ *  on the special device file
+ */
+/* Taken from hal/hald/linux/addons/addon-storage.c
+ * Copyright (C) 2004 David Zeuthen, 
+ * Licensed under the Academic Free License version 2.1
+*/
+static gboolean
+is_mounted (const char *device_file)
+{
+FILE *f;
+gboolean rc;
+struct mntent mnt;
+char buf[512];
+
+rc = FALSE;
+
+if ((f = setmntent ("/etc/mtab", "r")) == NULL)
+goto out;
+
+while (getmntent_r (f, &mnt, buf, sizeof(buf)) != NULL) {
+if (strcmp (device_file, mnt.mnt_fsname) == 0) {
+rc = TRUE;
+goto out1;
+}
+}
+
+out1:
+endmntent (f);
+out:
+return rc;
+}
+
 static void
 poller_poll_device (const gchar *device_file)
 {
@@ -126,6 +164,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
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel


Re: [udisks] CD-ROM polling failed due to O_EXCL flag (poller.c)

2011-02-26 Thread PCMan
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  wrote:
> On Fri, Feb 25, 2011 at 14:47, PCMan  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) 
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
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel


Re: policykit authentication agent with dbus

2012-06-20 Thread PCMan
On Thu, Jun 21, 2012 at 2:17 AM, Kevin Chadwick  wrote:
>> I want to implement a policy agent for kde3 and I want to use only dbus 
>> calls.
>
> What's so good about dbus. For years Windows has been criticised for
> it's abundant use of difficult to secure RPC. (Ever disabled RPC on
> Windows?, quite amusing). IPC over usage is worrying. IPC on QNXs
> microkernel may add to reliability for driver distancing but it also
> adds major security problems and other instabilities.
>
> 
>
>  Why not do something good every day and install BOINC.
> 
> ___
> devkit-devel mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/devkit-devel

Looks like it uses ConsoleKit?
org.freedesktop.ConsoleKit
/org/freedesktop/ConsoleKit/Manager
org.freedesktop.ConsoleKit.Manager
GetSessionForUnixProcess

I read its source code and found this.
___
devkit-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/devkit-devel