Skip to content

Commit

Permalink
Drop udev dependency, rely on the newer systemd APIs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Jan 16, 2023
1 parent f6fc43f commit 89b3fef
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 44 deletions.
2 changes: 0 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down Expand Up @@ -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')
Expand Down
5 changes: 0 additions & 5 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
55 changes: 23 additions & 32 deletions src/as-system-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#ifdef HAVE_UDEV
#include <libudev.h>
#endif
#ifdef HAVE_SYSTEMD
#include <systemd/sd-hwdb.h>
#include <systemd/sd-device.h>
#endif

#include "as-utils-private.h"
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion tests/ci/install-deps-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion tests/ci/install-deps-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)' \
Expand Down
4 changes: 2 additions & 2 deletions tools/ascli-actions-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 89b3fef

Please sign in to comment.