From ad461d504df67e32db72e1d86136f1dba08b3aa3 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Tue, 30 Aug 2022 23:53:36 -0500 Subject: [PATCH] bios-settings: Fix plugin functionality By moving the attribute loading into udev it was loading too late and plugins couldn't use it. Move the loading to earlier in the daemon and ignore add events if we already have attributes loaded. Fixes: #4979 --- libfwupdplugin/fu-context.c | 4 +++- src/fu-engine.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libfwupdplugin/fu-context.c b/libfwupdplugin/fu-context.c index e1a9d51de..b0aa42fe2 100644 --- a/libfwupdplugin/fu-context.c +++ b/libfwupdplugin/fu-context.c @@ -590,6 +590,7 @@ fu_context_load_hwinfo(FuContext *self, GError **error) GPtrArray *guids; g_autoptr(GError) error_smbios = NULL; g_autoptr(GError) error_hwids = NULL; + g_autoptr(GError) error_bios_settings = NULL; g_return_val_if_fail(FU_IS_CONTEXT(self), FALSE); g_return_val_if_fail(error == NULL || *error == NULL, FALSE); @@ -614,8 +615,9 @@ fu_context_load_hwinfo(FuContext *self, GError **error) } } - /* set it up so that udev will load firmware attributes */ fu_context_add_udev_subsystem(self, "firmware-attributes"); + if (!fu_context_reload_bios_settings(self, &error_bios_settings)) + g_debug("%s", error_bios_settings->message); /* always */ return TRUE; diff --git a/src/fu-engine.c b/src/fu-engine.c index f2fd2c348..fa0e770d6 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -6926,7 +6926,7 @@ fu_engine_apply_default_bios_settings_policy(FuEngine *self, GError **error) } static void -fu_engine_check_firmware_attributes(FuEngine *self, FuDevice *device) +fu_engine_check_firmware_attributes(FuEngine *self, FuDevice *device, gboolean added) { const gchar *subsystem; @@ -6937,6 +6937,15 @@ fu_engine_check_firmware_attributes(FuEngine *self, FuDevice *device) subsystem = fu_udev_device_get_subsystem(FU_UDEV_DEVICE(device)); if (g_strcmp0(subsystem, "firmware-attributes") == 0) { g_autoptr(GError) error = NULL; + if (added) { + FuBiosSettings *settings = fu_context_get_bios_settings(self->ctx); + g_autoptr(GPtrArray) items = fu_bios_settings_get_all(settings); + + if (items->len > 0) { + g_debug("ignoring add event for already loaded settings"); + return; + } + } if (!fu_context_reload_bios_settings(self->ctx, &error)) { g_debug("%s", error->message); return; @@ -6958,7 +6967,7 @@ fu_engine_backend_device_removed_cb(FuBackend *backend, FuDevice *device, FuEngi g_autoptr(GPtrArray) devices = NULL; /* if this is for firmware attributes, reload that part of the daemon */ - fu_engine_check_firmware_attributes(self, device); + fu_engine_check_firmware_attributes(self, device, FALSE); /* debug */ if (g_getenv("FWUPD_PROBE_VERBOSE") != NULL) { @@ -7101,7 +7110,7 @@ fu_engine_backend_device_added(FuEngine *self, FuDevice *device, FuProgress *pro } /* if this is for firmware attributes, reload that part of the daemon */ - fu_engine_check_firmware_attributes(self, device); + fu_engine_check_firmware_attributes(self, device, TRUE); /* can be specified using a quirk */ fu_engine_backend_device_added_run_plugins(self, device, fu_progress_get_child(progress));