[gvfs/wip/inigomartinez/meson: 6/9] metadata: Remove udev dependency in favor of gudev



commit 070acae266500be7b0421440b2a72ebb9a3434d6
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Oct 24 16:12:39 2017 +0200

    metadata: Remove udev dependency in favor of gudev
    
    GVfs uses udev and also gudev. Let's use just gudev and remove corresponding
    --enable-udev option.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786149

 meson.build            |    7 -------
 metadata/meson.build   |    2 +-
 metadata/meta-daemon.c |   44 +++++++++++++++++++-------------------------
 3 files changed, 20 insertions(+), 33 deletions(-)
---
diff --git a/meson.build b/meson.build
index 589919c..8d977a7 100644
--- a/meson.build
+++ b/meson.build
@@ -336,13 +336,6 @@ if enable_dnssd
 endif
 config_h.set('HAVE_AVAHI', enable_dnssd)
 
-# *** Check for libudev ***
-enable_udev = get_option('enable-udev')
-if enable_udev
-  libudev_dep = dependency('libudev', version: '>= 138')
-endif
-config_h.set('HAVE_LIBUDEV', enable_udev)
-
 # *** Check for gudev ***
 enable_gudev = get_option('enable-gudev')
 if enable_gudev
diff --git a/metadata/meson.build b/metadata/meson.build
index 303280f..474dd04 100644
--- a/metadata/meson.build
+++ b/metadata/meson.build
@@ -62,7 +62,7 @@ executable(
   dependencies: [
     libgvfscommon_dep,
     libmetadata_dep,
-    libudev_dep
+    gudev_dep
   ],
   c_args: cflags,
   install: true,
diff --git a/metadata/meta-daemon.c b/metadata/meta-daemon.c
index 17402df..444a439 100644
--- a/metadata/meta-daemon.c
+++ b/metadata/meta-daemon.c
@@ -31,9 +31,8 @@
 #include "gvfsdaemonprotocol.h"
 #include "metadata-dbus.h"
 
-#ifdef HAVE_LIBUDEV
-#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
-#include <libudev.h>
+#ifdef HAVE_GUDEV
+#include <gudev/gudev.h>
 #endif
 
 #if MAJOR_IN_MKDEV
@@ -53,6 +52,9 @@ typedef struct {
 
 static GHashTable *tree_infos = NULL;
 static GVfsMetadata *skeleton = NULL;
+#ifdef HAVE_GUDEV
+static GUdevClient *gudev_client = NULL;
+#endif
 
 static void
 tree_info_free (TreeInfo *info)
@@ -309,32 +311,21 @@ handle_get_tree_from_device (GVfsMetadata *object,
 {
   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 ();
+#ifdef HAVE_GUDEV
+  GUdevDeviceNumber devnum = makedev (arg_major, arg_minor);
+  GUdevDevice *device;
 
-  dev = udev_device_new_from_devnum (udev, 'b', devnum);
-  uuid = udev_device_get_property_value (dev, "ID_FS_UUID_ENC");
+  if (g_once_init_enter (&gudev_client))
+    g_once_init_leave (&gudev_client, g_udev_client_new (NULL));
 
-  res = NULL;
-  if (uuid)
-    {
-      res = g_strconcat ("uuid-", uuid, NULL);
-    }
-  else
-    {
-      label = udev_device_get_property_value (dev, "ID_FS_LABEL_ENC");
+  device = g_udev_client_query_by_device_number (gudev_client, G_UDEV_DEVICE_TYPE_BLOCK, devnum);
 
-      if (label)
-        res = g_strconcat ("label-", label, NULL);
-    }
+  if (g_udev_device_has_property (device, "ID_FS_UUID_ENC"))
+    res = g_strconcat ("uuid-", g_udev_device_get_property (device, "ID_FS_UUID_ENC"), NULL);
+  else if (g_udev_device_has_property (device, "ID_FS_LABEL_ENC"))
+    res = g_strconcat ("label-", g_udev_device_get_property (device, "ID_FS_LABEL_ENC"), NULL);
 
-  udev_device_unref (dev);
+  g_clear_object (&device);
 #endif
 
   gvfs_metadata_complete_get_tree_from_device (object, invocation, res ? res : "");
@@ -485,6 +476,9 @@ main (int argc, char *argv[])
     g_object_unref (conn);
   if (loop != NULL)
     g_main_loop_unref (loop);
+#ifdef HAVE_GUDEV
+  g_clear_object (&gudev_client);
+#endif
 
   return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]