summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2012-04-22 10:07:23 -0400
committerDavid Zeuthen <davidz@redhat.com>2012-04-22 10:07:23 -0400
commit11dbea1c6655f101db541e7258bcb91b0e5d2a8d (patch)
treeeefbf14380ae3c75f4aca81deb145c55d32a6fd0
parentd1782cf834ef4baff8ffd1c91305f80dbf9a6640 (diff)
downloadudisks-11dbea1c6655f101db541e7258bcb91b0e5d2a8d.tar.gz
Make on_same_seat() also work for drive objects
Otherwise it won't work when used for the Drive.Eject() method which operates on a Drive object instead of a Block object. Also use Drive:seat instead of peeking into the udev database. Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--src/udisksdaemonutil.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c
index fa65328..7ea1097 100644
--- a/src/udisksdaemonutil.c
+++ b/src/udisksdaemonutil.c
@@ -35,6 +35,7 @@
#include "udiskscleanup.h"
#include "udiskslogging.h"
#include "udiskslinuxblockobject.h"
+#include "udiskslinuxdriveobject.h"
#if defined(HAVE_LIBSYSTEMD_LOGIN)
#include <systemd/sd-login.h>
@@ -804,6 +805,8 @@ udisks_daemon_util_escape (const gchar *str)
* Checks whether the device represented by @object (if any) is plugged into
* a seat where the caller represented by @process is logged in.
*
+ * This works if @object is a drive or a block object.
+ *
* Returns: %TRUE if @object and @process is on the same seat, %FALSE otherwise.
*/
gboolean
@@ -816,18 +819,34 @@ udisks_daemon_util_on_same_seat (UDisksDaemon *daemon,
return TRUE;
#else
gboolean ret = FALSE;
- GUdevDevice *device = NULL;
- UDisksLinuxBlockObject *linux_block_object;
char *session = NULL;
char *seat = NULL;
- const gchar *device_seat;
+ const gchar *drive_seat;
+ UDisksObject *drive_object = NULL;
+ UDisksDrive *drive = NULL;
+
+ if (UDISKS_IS_LINUX_BLOCK_OBJECT (object))
+ {
+ UDisksLinuxBlockObject *linux_block_object;
+ UDisksBlock *block;
+ linux_block_object = UDISKS_LINUX_BLOCK_OBJECT (object);
+ block = udisks_object_get_block (UDISKS_OBJECT (linux_block_object));
+ if (block != NULL)
+ {
+ drive_object = udisks_daemon_find_object (daemon, udisks_block_get_drive (block));
+ g_object_unref (block);
+ }
+ }
+ else if (UDISKS_IS_LINUX_DRIVE_OBJECT (object))
+ {
+ drive_object = UDISKS_OBJECT (object);
+ }
- if (!UDISKS_IS_LINUX_BLOCK_OBJECT (object))
+ if (drive_object == NULL)
goto out;
- linux_block_object = UDISKS_LINUX_BLOCK_OBJECT (object);
- device = udisks_linux_block_object_get_device (linux_block_object);
- if (device == NULL)
+ drive = udisks_object_get_drive (UDISKS_OBJECT (drive_object));
+ if (drive == NULL)
goto out;
/* It's not unexpected to not find a session, nor a seat associated with @process */
@@ -839,11 +858,11 @@ udisks_daemon_util_on_same_seat (UDisksDaemon *daemon,
goto out;
/* Assume device belongs to "seat0" if not tagged */
- device_seat = g_udev_device_get_property (device, "ID_SEAT");
- if (device_seat == NULL)
- device_seat = "seat0";
+ drive_seat = udisks_drive_get_seat (drive);
+ if (drive_seat == NULL || strlen (drive_seat) == 0)
+ drive_seat = "seat0";
- if (g_strcmp0 (seat, device_seat) == 0)
+ if (g_strcmp0 (seat, drive_seat) == 0)
{
ret = TRUE;
}
@@ -851,7 +870,8 @@ udisks_daemon_util_on_same_seat (UDisksDaemon *daemon,
out:
free (seat);
free (session);
- g_clear_object (&device);
+ g_clear_object (&drive_object);
+ g_clear_object (&drive);
return ret;
#endif /* HAVE_LIBSYSTEMD_LOGIN */
}