summaryrefslogtreecommitdiff
path: root/monitor/udisks2
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2012-04-21 12:28:09 -0400
committerDavid Zeuthen <davidz@redhat.com>2012-04-21 12:33:30 -0400
commit5c9ffd7bf5d08c3fe57e235d8001e0b9c23a2730 (patch)
treecbbd07132aa98ba014ffcde5e33b0097c89b45cd /monitor/udisks2
parentb51b55b8a7e66cabecec972c96513edce6237193 (diff)
downloadgvfs-5c9ffd7bf5d08c3fe57e235d8001e0b9c23a2730.tar.gz
Don't set should_automount to TRUE for devices on other seats
This change uses the libsystemd-login library to obtain the seat we're on and compares it against the Seat property on the D-Bus interface org.freedesktop.UDisks2.Drive. This property is available in udisks 1.95.0, see http://cgit.freedesktop.org/udisks/commit/?id=91106cdc7622d9674f6083dcb524407f026a36c7 Also, since we're still on the stable branch and not everyone may be using systemd, make this work without hard-requiring either libsystemd-login or udisks 1.95.0. Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'monitor/udisks2')
-rw-r--r--monitor/udisks2/Makefile.am2
-rw-r--r--monitor/udisks2/gvfsudisks2volume.c125
2 files changed, 102 insertions, 25 deletions
diff --git a/monitor/udisks2/Makefile.am b/monitor/udisks2/Makefile.am
index f919df61..776f6708 100644
--- a/monitor/udisks2/Makefile.am
+++ b/monitor/udisks2/Makefile.am
@@ -19,6 +19,7 @@ gvfs_udisks2_volume_monitor_CFLAGS = \
$(GLIB_CFLAGS) \
$(UDISKS2_CFLAGS) \
$(GUDEV_CFLAGS) \
+ $(LIBSYSTEMD_LOGIN_CFLAGS) \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
-DG_DISABLE_DEPRECATED \
@@ -32,6 +33,7 @@ gvfs_udisks2_volume_monitor_LDADD = \
$(GLIB_LIBS) \
$(UDISKS2_LIBS) \
$(GUDEV_LIBS) \
+ $(LIBSYSTEMD_LOGIN_LIBS) \
$(top_builddir)/common/libgvfscommon.la \
$(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \
$(NULL)
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index 89c24136..243dc148 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -36,6 +36,41 @@
#include "gvfsudisks2mount.h"
#include "gvfsudisks2utils.h"
+
+#if defined(HAVE_LIBSYSTEMD_LOGIN)
+#include <systemd/sd-login.h>
+
+static const gchar *
+get_seat (void)
+{
+ static gsize once = 0;
+ static char *seat = NULL;
+
+ if (g_once_init_enter (&once))
+ {
+ char *session = NULL;
+ if (sd_pid_get_session (getpid (), &session) == 0)
+ {
+ sd_session_get_seat (session, &seat);
+ /* we intentionally leak seat here... */
+ }
+ g_once_init_leave (&once, (gsize) 1);
+ }
+ return seat;
+}
+
+#else
+
+static const gchar *
+get_seat (void)
+{
+ return NULL;
+}
+
+#endif
+
+
+
typedef struct _GVfsUDisks2VolumeClass GVfsUDisks2VolumeClass;
struct _GVfsUDisks2VolumeClass
@@ -178,6 +213,43 @@ apply_options_from_fstab (GVfsUDisks2Volume *volume,
}
static gboolean
+drive_is_on_our_seat (UDisksDrive *drive)
+{
+ gboolean ret = FALSE;
+ const gchar *seat;
+ const gchar *drive_seat = NULL;
+
+ /* assume our own seat if we don't have seat-support or it doesn't work */
+ seat = get_seat ();
+ if (seat == NULL)
+ {
+ ret = TRUE;
+ goto out;
+ }
+
+ /* Assume seat0 if a) device is not tagged; or b) udisks does not
+ * have seat-support.
+ *
+ * Note that seat support was added in udisks 1.95.0 (and so was the
+ * UDISKS_CHECK_VERSION macro) - for now, be compatible with older
+ * versions instead of bumping requirement in configure.ac
+ */
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,95,0)
+ drive_seat = udisks_drive_get_seat (drive);
+# endif
+#endif
+ if (drive_seat == NULL || strlen (drive_seat) == 0)
+ drive_seat = "seat0";
+
+ if (g_strcmp0 (seat, drive_seat) == 0)
+ ret = TRUE;
+
+ out:
+ return ret;
+}
+
+static gboolean
update_volume (GVfsUDisks2Volume *volume)
{
gboolean changed;
@@ -314,35 +386,38 @@ update_volume (GVfsUDisks2Volume *volume)
if (media_icon != NULL)
g_object_unref (media_icon);
- /* Only automount filesystems from drives of known types/interconnects:
- *
- * - USB
- * - Firewire
- * - sdio
- * - optical discs
- *
- * The mantra here is "be careful" - we really don't want to
- * automount filesystems from all devices in a SAN etc - We
- * REALLY need to be CAREFUL here.
- *
- * Fortunately udisks provides a property just for this.
- */
- if (udisks_block_get_hint_auto (volume->block))
+ /* Only automount drives attached to the same seat as we're running on */
+ if (drive_is_on_our_seat (udisks_drive))
{
- gboolean just_plugged_in = FALSE;
- /* Also, if a volume (partition) appear _much later_ than when media was inserted it
- * can only be because the media was repartitioned. We don't want to automount
- * such volumes. So only mark volumes appearing just after their drive.
+ /* Only automount filesystems from drives of known types/interconnects:
*
- * There's a catch here - if the volume was discovered at coldplug-time (typically
- * when the user desktop session started), we can't use this heuristic
+ * - USB
+ * - Firewire
+ * - sdio
+ * - optical discs
+ *
+ * The mantra here is "be careful" - we really don't want to
+ * automount filesystems from all devices in a SAN etc - We
+ * REALLY need to be CAREFUL here.
+ *
+ * Fortunately udisks provides a property just for this.
*/
- if (g_get_real_time () - udisks_drive_get_time_media_detected (udisks_drive) < 5 * G_USEC_PER_SEC)
- just_plugged_in = TRUE;
- if (volume->coldplug || just_plugged_in)
- volume->should_automount = TRUE;
+ if (udisks_block_get_hint_auto (volume->block))
+ {
+ gboolean just_plugged_in = FALSE;
+ /* Also, if a volume (partition) appear _much later_ than when media was inserted it
+ * can only be because the media was repartitioned. We don't want to automount
+ * such volumes. So only mark volumes appearing just after their drive.
+ *
+ * There's a catch here - if the volume was discovered at coldplug-time (typically
+ * when the user desktop session started), we can't use this heuristic
+ */
+ if (g_get_real_time () - udisks_drive_get_time_media_detected (udisks_drive) < 5 * G_USEC_PER_SEC)
+ just_plugged_in = TRUE;
+ if (volume->coldplug || just_plugged_in)
+ volume->should_automount = TRUE;
+ }
}
-
g_object_unref (udisks_drive);
}