summaryrefslogtreecommitdiff
path: root/metadata
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2015-05-29 13:06:16 +0200
committerOndrej Holy <oholy@redhat.com>2015-06-01 09:36:30 +0200
commitb78cc85d2dda10e5488cf23cb63008ca339836dc (patch)
treef61c2c384fb5320ea9216b69c41d4fd85d5ff0c2 /metadata
parent95bf3840548e9493d075fdd8b3bcec1fe569cc7a (diff)
downloadgvfs-b78cc85d2dda10e5488cf23cb63008ca339836dc.tar.gz
metadata: Get tree from udev via dbus
We don't want to have dependency on udev in client part of gvfs due to app sandboxing. Thus move the code into the metadata daemon and get tree name via dbus. Common code to get metadata proxy has to be moved in metatree code. Mentioned changes caused that unistd.h is also included in meta-get-tree.c and cause symbol redeclaration error. Variable "pause" has to be renamed to avoid this conflict.
Diffstat (limited to 'metadata')
-rw-r--r--metadata/Makefile.am6
-rw-r--r--metadata/dbus-interface.xml5
-rw-r--r--metadata/meta-daemon.c48
-rw-r--r--metadata/meta-get-tree.c6
-rw-r--r--metadata/metatree.c103
-rw-r--r--metadata/metatree.h4
6 files changed, 116 insertions, 56 deletions
diff --git a/metadata/Makefile.am b/metadata/Makefile.am
index 767033e1..905e8057 100644
--- a/metadata/Makefile.am
+++ b/metadata/Makefile.am
@@ -32,7 +32,6 @@ libexec_PROGRAMS =\
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/common \
$(LIBXML_CFLAGS) $(GLIB_CFLAGS) \
- $(UDEV_CFLAGS) \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
-DG_LOG_DOMAIN=\"GVFS\" \
-DDBUS_API_SUBJECT_TO_CHANGE
@@ -44,7 +43,7 @@ libmetadata_la_SOURCES = \
$(dbus_built_sources) \
$(NULL)
-libmetadata_la_LIBADD = $(GLIB_LIBS) $(UDEV_LIBS)
+libmetadata_la_LIBADD = $(GLIB_LIBS)
meta_ls_LDADD = libmetadata.la ../common/libgvfscommon.la
meta_ls_SOURCES = meta-ls.c
@@ -61,8 +60,9 @@ meta_get_tree_SOURCES = meta-get-tree.c
convert_nautilus_metadata_LDADD = libmetadata.la $(LIBXML_LIBS)
convert_nautilus_metadata_SOURCES = metadata-nautilus.c
-gvfsd_metadata_LDADD = libmetadata.la ../common/libgvfscommon.la
+gvfsd_metadata_LDADD = libmetadata.la ../common/libgvfscommon.la $(UDEV_LIBS)
gvfsd_metadata_SOURCES = meta-daemon.c
+gvfsd_metadata_CFLAFGS = $(UDEV_CFLAGS)
# D-BUS service file
%.service: %.service.in ../config.log
diff --git a/metadata/dbus-interface.xml b/metadata/dbus-interface.xml
index 263994a3..990a95cb 100644
--- a/metadata/dbus-interface.xml
+++ b/metadata/dbus-interface.xml
@@ -40,6 +40,11 @@
<arg type='ay' name='path' direction='in'/>
<arg type='ay' name='dest_path' direction='in'/>
</method>
+ <method name="GetTreeFromDevice">
+ <arg type='u' name='major' direction='in'/>
+ <arg type='u' name='minor' direction='in'/>
+ <arg type='s' name='tree' direction='out'/>
+ </method>
</interface>
</node>
diff --git a/metadata/meta-daemon.c b/metadata/meta-daemon.c
index d3643d17..984ee7f9 100644
--- a/metadata/meta-daemon.c
+++ b/metadata/meta-daemon.c
@@ -31,6 +31,11 @@
#include "gvfsdaemonprotocol.h"
#include "metadata-dbus.h"
+#ifdef HAVE_LIBUDEV
+#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
+#include <libudev.h>
+#endif
+
#define WRITEOUT_TIMEOUT_SECS 60
#define WRITEOUT_TIMEOUT_SECS_NFS 15
@@ -290,6 +295,48 @@ handle_move (GVfsMetadata *object,
return TRUE;
}
+static gboolean
+handle_get_tree_from_device (GVfsMetadata *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_major,
+ guint arg_minor)
+{
+ char *res = NULL;
+
+#ifdef HAVE_LIBUDEV
+ dev_t devnum = makedev (arg_major, arg_minor);
+ struct udev_device *dev;
+ const char *uuid, *label;
+ static struct udev *udev;
+
+ if (udev == NULL)
+ udev = udev_new ();
+
+ dev = udev_device_new_from_devnum (udev, 'b', devnum);
+ uuid = udev_device_get_property_value (dev, "ID_FS_UUID_ENC");
+
+ res = NULL;
+ if (uuid)
+ {
+ res = g_strconcat ("uuid-", uuid, NULL);
+ }
+ else
+ {
+ label = udev_device_get_property_value (dev, "ID_FS_LABEL_ENC");
+
+ if (label)
+ res = g_strconcat ("label-", label, NULL);
+ }
+
+ udev_device_unref (dev);
+#endif
+
+ gvfs_metadata_complete_get_tree_from_device (object, invocation, res ? res : "");
+ g_free (res);
+
+ return TRUE;
+}
+
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
@@ -400,6 +447,7 @@ main (int argc, char *argv[])
g_signal_connect (skeleton, "handle-set", G_CALLBACK (handle_set), skeleton);
g_signal_connect (skeleton, "handle-remove", G_CALLBACK (handle_remove), skeleton);
g_signal_connect (skeleton, "handle-move", G_CALLBACK (handle_move), skeleton);
+ g_signal_connect (skeleton, "handle-get-tree-from-device", G_CALLBACK (handle_get_tree_from_device), skeleton);
error = NULL;
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton), conn,
diff --git a/metadata/meta-get-tree.c b/metadata/meta-get-tree.c
index 23ce9e42..e4f29816 100644
--- a/metadata/meta-get-tree.c
+++ b/metadata/meta-get-tree.c
@@ -4,11 +4,11 @@
/*static gboolean recursive = FALSE;*/
static gboolean verbose = FALSE;
-static gboolean pause = FALSE;
+static gboolean do_pause = FALSE;
static GOptionEntry entries[] =
{
{ "verbose", 'l', 0, G_OPTION_ARG_NONE, &verbose, "Verbose", NULL },
- { "pause", 'p', 0, G_OPTION_ARG_NONE, &pause, "Pause", NULL },
+ { "pause", 'p', 0, G_OPTION_ARG_NONE, &do_pause, "Pause", NULL },
{ NULL }
};
@@ -51,7 +51,7 @@ main (int argc,
else
g_print ("tree lookup failed\n");
- if (pause)
+ if (do_pause)
{
char buffer[1000];
g_print ("Pausing, press enter\n");
diff --git a/metadata/metatree.c b/metadata/metatree.c
index 4964c682..59be3dfe 100644
--- a/metadata/metatree.c
+++ b/metadata/metatree.c
@@ -15,11 +15,8 @@
#include <glib/gstdio.h>
#include "gvfsutils.h"
#include "crc32.h"
-
-#ifdef HAVE_LIBUDEV
-#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
-#include <libudev.h>
-#endif
+#include "metadata-dbus.h"
+#include "gvfsdaemonprotocol.h"
#define MAGIC "\xda\x1ameta"
#define MAGIC_LEN 6
@@ -163,6 +160,34 @@ static MetaJournal *meta_journal_open (MetaTree *tree,
static void meta_journal_free (MetaJournal *journal);
static void meta_journal_validate_more (MetaJournal *journal);
+GVfsMetadata *
+meta_tree_get_metadata_proxy ()
+{
+ static GVfsMetadata *proxy = NULL;
+ static volatile gsize initialized = 0;
+
+ if (g_once_init_enter (&initialized))
+ {
+ GError *error = NULL;
+
+ proxy = gvfs_metadata_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ G_VFS_DBUS_METADATA_NAME,
+ G_VFS_DBUS_METADATA_PATH,
+ NULL,
+ &error);
+ if (error)
+ {
+ g_warning ("Error: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_once_init_leave (&initialized, 1);
+ }
+
+ return proxy;
+}
+
static gpointer
verify_block_pointer (MetaTree *tree, guint32 pos, guint32 len)
{
@@ -2811,63 +2836,41 @@ struct _MetaLookupCache {
char *last_device_tree;
};
-#ifdef HAVE_LIBUDEV
-
-static struct udev *udev;
-G_LOCK_DEFINE_STATIC (udev);
-
-static char *
-get_tree_from_udev (MetaLookupCache *cache,
- dev_t devnum)
-{
- struct udev_device *dev;
- const char *uuid, *label;
- char *res;
-
- G_LOCK (udev);
-
- if (udev == NULL)
- udev = udev_new ();
-
- dev = udev_device_new_from_devnum (udev, 'b', devnum);
- uuid = udev_device_get_property_value (dev, "ID_FS_UUID_ENC");
-
- res = NULL;
- if (uuid)
- {
- res = g_strconcat ("uuid-", uuid, NULL);
- }
- else
- {
- label = udev_device_get_property_value (dev, "ID_FS_LABEL_ENC");
-
- if (label)
- res = g_strconcat ("label-", label, NULL);
- }
-
- udev_device_unref (dev);
-
- G_UNLOCK (udev);
-
- return res;
-}
-#endif
static const char *
get_tree_for_device (MetaLookupCache *cache,
dev_t device)
{
-#ifdef HAVE_LIBUDEV
+ gchar *res = NULL;
+
if (device != cache->last_device)
{
+ GError *error = NULL;
+ GVfsMetadata *metadata_proxy;
+
+ metadata_proxy = meta_tree_get_metadata_proxy ();
+ if (metadata_proxy != NULL)
+ gvfs_metadata_call_get_tree_from_device_sync (metadata_proxy,
+ major (device),
+ minor (device),
+ &res,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ g_warning ("Error: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ if (res && res[0] == '\0')
+ g_clear_pointer (&res, g_free);
cache->last_device = device;
g_free (cache->last_device_tree);
- cache->last_device_tree = get_tree_from_udev (cache, device);
+ cache->last_device_tree = res;
}
return cache->last_device_tree;
-#endif
- return NULL;
}
diff --git a/metadata/metatree.h b/metadata/metatree.h
index d469b98e..46dd02bd 100644
--- a/metadata/metatree.h
+++ b/metadata/metatree.h
@@ -24,6 +24,7 @@
#define __META_TREE_H__
#include <glib.h>
+#include "metadata-dbus.h"
typedef struct _MetaTree MetaTree;
typedef struct _MetaLookupCache MetaLookupCache;
@@ -104,4 +105,7 @@ gboolean meta_tree_remove (MetaTree *tree,
gboolean meta_tree_copy (MetaTree *tree,
const char *src,
const char *dest);
+
+GVfsMetadata *meta_tree_get_metadata_proxy (void);
+
#endif /* __META_TREE_H__ */