From 89b3fef9e2600921afd40f645cbc9b059bb53053 Mon Sep 17 00:00:00 2001 From: Matthias Klumpp Date: Mon, 16 Jan 2023 02:55:07 +0100 Subject: [PATCH] Drop udev dependency, rely on the newer systemd APIs instead --- meson.build | 2 -- meson_options.txt | 5 ---- src/as-system-info.c | 55 +++++++++++++++--------------------- src/meson.build | 1 - tests/ci/install-deps-deb.sh | 1 - tests/ci/install-deps-rpm.sh | 1 - tools/ascli-actions-misc.c | 4 +-- 7 files changed, 25 insertions(+), 44 deletions(-) diff --git a/meson.build b/meson.build index 8c36cc999..69a8b4285 100644 --- a/meson.build +++ b/meson.build @@ -50,7 +50,6 @@ conf.set_quoted('SYSCONFDIR', conf.set('_DEFAULT_SOURCE', true) conf.set('HAVE_APT_SUPPORT', get_option('apt-support')) conf.set('HAVE_STEMMING', get_option('stemming')) -conf.set('HAVE_UDEV', get_option('udev')) conf.set('HAVE_SYSTEMD', get_option('systemd')) conf.set('HAVE_SVG_SUPPORT', get_option('svg-support')) @@ -163,7 +162,6 @@ xml2_dep = dependency('libxml-2.0') yaml_dep = dependency('yaml-0.1') xmlb_dep = dependency('xmlb', version: '>= 0.3.6', fallback: ['libxmlb', 'libxmlb_dep'], default_options: ['gtkdoc=false']) -libudev_dep = dependency('libudev', required: get_option('udev')) libsystemd_dep = dependency('libsystemd', required: get_option('systemd')) if get_option ('gir') diff --git a/meson_options.txt b/meson_options.txt index 6bf42f032..22f32cae4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,11 +3,6 @@ option('stemming', value : true, description : 'Use stemming while searching. Requires Snowball (libstemmer)' ) -option('udev', - type : 'boolean', - value : true, - description : 'Build with udev support' -) option('systemd', type : 'boolean', value : true, diff --git a/src/as-system-info.c b/src/as-system-info.c index 1eba34707..ad17c7ed8 100644 --- a/src/as-system-info.c +++ b/src/as-system-info.c @@ -48,11 +48,9 @@ #include #include #endif -#ifdef HAVE_UDEV -#include -#endif #ifdef HAVE_SYSTEMD #include +#include #endif #include "as-utils-private.h" @@ -74,9 +72,7 @@ typedef struct GPtrArray *modaliases; GHashTable *modalias_to_sysfs; -#ifdef HAVE_UDEV - struct udev *udev; -#endif + #ifdef HAVE_SYSTEMD sd_hwdb *hwdb; #endif @@ -121,10 +117,7 @@ as_system_info_finalize (GObject *object) g_ptr_array_unref (priv->modaliases); g_hash_table_unref (priv->modalias_to_sysfs); -#ifdef HAVE_UDEV - if (priv->udev != NULL) - udev_unref (priv->udev); -#endif + #ifdef HAVE_SYSTEMD if (priv->hwdb != NULL) sd_hwdb_unref (priv->hwdb); @@ -520,21 +513,18 @@ as_system_info_get_device_name_from_syspath (AsSystemInfo *sysinfo, gboolean allow_fallback, GError **error) { -#ifdef HAVE_UDEV - AsSystemInfoPrivate *priv = GET_PRIVATE (sysinfo); - struct udev_device *device; - struct udev_list_entry *entry, *e; +#ifdef HAVE_SYSTEMD + __attribute__((cleanup (sd_device_unrefp))) sd_device *device = NULL; + const gchar *key, *value; + gint r; const gchar *device_vendor = NULL; const gchar *device_model = NULL; const gchar *usb_class = NULL; const gchar *driver = NULL; gchar *result = NULL; - if (priv->udev == NULL) - priv->udev = udev_new (); - - device = udev_device_new_from_syspath (priv->udev, syspath); - if (device == NULL) { + r = sd_device_new_from_syspath (&device, syspath); + if (r < 0) { g_set_error (error, AS_SYSTEM_INFO_ERROR, AS_SYSTEM_INFO_ERROR_FAILED, @@ -543,17 +533,19 @@ as_system_info_get_device_name_from_syspath (AsSystemInfo *sysinfo, return NULL; } - entry = udev_device_get_properties_list_entry (device); - udev_list_entry_foreach(e, entry) { - const gchar *e_name = udev_list_entry_get_name (e); - if (g_strstr_len (e_name, -1, "_VENDOR") != NULL) - device_vendor = udev_list_entry_get_value (e); - else if (g_strstr_len (e_name, -1, "_MODEL") != NULL) - device_model = udev_list_entry_get_value (e); - else if (as_str_equal0 (e_name, "DRIVER")) - driver = udev_list_entry_get_value (e); - else if (g_strstr_len (e_name, -1, "_USB_CLASS")) - usb_class = udev_list_entry_get_value (e); + for (key = sd_device_get_property_first (device, &value); + key; + key = sd_device_get_property_next (device, &value)) { + if (g_strstr_len (key, -1, "_VENDOR") != NULL) { + if (g_strstr_len (key, -1, "VENDOR_ID") == NULL && !g_str_has_suffix (key, "_ENC")) + device_vendor = value; + } else if (g_strstr_len (key, -1, "_MODEL") != NULL) { + if (g_strstr_len (key, -1, "MODEL_ID") == NULL && !g_str_has_suffix (key, "_ENC")) + device_model = value; + } else if (as_str_equal0 (key, "DRIVER")) + driver = value; + else if (g_strstr_len (key, -1, "_USB_CLASS")) + usb_class = value; } if (device_vendor != NULL) { @@ -577,13 +569,12 @@ as_system_info_get_device_name_from_syspath (AsSystemInfo *sysinfo, } } - udev_device_unref (device); return result; #else g_set_error_literal (error, AS_SYSTEM_INFO_ERROR, AS_SYSTEM_INFO_ERROR_FAILED, - "Unable to determine device name: AppStream was built without udev support."); + "Unable to determine device name: AppStream was built without systemd-udevd support."); return NULL; #endif } diff --git a/src/meson.build b/src/meson.build index 947fe1e44..c041cfe72 100644 --- a/src/meson.build +++ b/src/meson.build @@ -176,7 +176,6 @@ aslib_deps = [glib_dep, xmlb_dep, xml2_dep, yaml_dep, - libudev_dep, libsystemd_dep] if get_option ('stemming') aslib_deps += [stemmer_lib] diff --git a/tests/ci/install-deps-deb.sh b/tests/ci/install-deps-deb.sh index 8412cd4d9..9fc437bd8 100755 --- a/tests/ci/install-deps-deb.sh +++ b/tests/ci/install-deps-deb.sh @@ -31,7 +31,6 @@ eatmydata apt-get install -yq --no-install-recommends \ libxmlb-dev \ liblzma-dev \ libcurl4-gnutls-dev \ - libudev-dev \ libsystemd-dev \ gtk-doc-tools \ libgirepository1.0-dev \ diff --git a/tests/ci/install-deps-rpm.sh b/tests/ci/install-deps-rpm.sh index 4b01f5352..98d9f6f3d 100755 --- a/tests/ci/install-deps-rpm.sh +++ b/tests/ci/install-deps-rpm.sh @@ -28,7 +28,6 @@ dnf --assumeyes --quiet --setopt=install_weak_deps=False install \ 'pkgconfig(libxml-2.0)' \ 'pkgconfig(yaml-0.1)' \ 'pkgconfig(libcurl)' \ - 'pkgconfig(libudev)' \ 'pkgconfig(libsystemd)' \ 'pkgconfig(librsvg-2.0)' \ 'pkgconfig(cairo)' \ diff --git a/tools/ascli-actions-misc.c b/tools/ascli-actions-misc.c index 13bcf4407..01bf2b1b0 100644 --- a/tools/ascli-actions-misc.c +++ b/tools/ascli-actions-misc.c @@ -559,11 +559,11 @@ ascli_show_sysinfo (const gchar *cachepath, gboolean no_cache, gboolean detailed g_print ("\n"); ascli_print_highlight ("%s:", _("Hardware")); total_memory = as_system_info_get_memory_total (sysinfo); - ascli_print_stdout ("%s: %lu MiB (%.2f GiB)", _("Memory"), total_memory, total_memory / 1024.0); + ascli_print_stdout ("%s: %lu MiB (%.2f GiB)", _("Physical Memory"), total_memory, total_memory / 1024.0); modaliases = as_system_info_get_modaliases (sysinfo); if (modaliases->len > 0) { - ascli_print_stdout ("%s:", "Devices"); + ascli_print_stdout ("%s:", _("Devices with Modaliases")); for (guint i = 0; i < modaliases->len; i++) { g_autoptr(GError) tmp_error = NULL; g_autofree gchar *dev_name = NULL;