diff --git a/plugins/flashrom/fu-plugin-flashrom.c b/plugins/flashrom/fu-plugin-flashrom.c index 801d2fdff..084498ffb 100644 --- a/plugins/flashrom/fu-plugin-flashrom.c +++ b/plugins/flashrom/fu-plugin-flashrom.c @@ -48,9 +48,10 @@ fu_plugin_startup (FuPlugin *plugin, GError **error) { FuPluginData *data = fu_plugin_get_data (plugin); GPtrArray *hwids; + g_autoptr(GError) error_local = NULL; /* we need flashrom from the host system */ - data->flashrom_fn = g_find_program_in_path ("flashrom"); + data->flashrom_fn = fu_common_find_program_in_path ("flashrom", &error_local); /* search for devices */ hwids = fu_plugin_get_hwids (plugin); @@ -70,7 +71,7 @@ fu_plugin_startup (FuPlugin *plugin, GError **error) if (data->flashrom_fn != NULL) { fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE); } else { - fu_device_set_update_error (dev, "flashrom binary not found"); + fu_device_set_update_error (dev, error_local->message); } fu_device_add_guid (dev, guid); fu_device_set_name (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME)); diff --git a/plugins/uefi/fu-plugin-uefi.c b/plugins/uefi/fu-plugin-uefi.c index 2e3a416f4..203b854b8 100644 --- a/plugins/uefi/fu-plugin-uefi.c +++ b/plugins/uefi/fu-plugin-uefi.c @@ -381,7 +381,7 @@ fu_plugin_update (FuPlugin *plugin, return FALSE; /* record boot information to system log for future debugging */ - efibootmgr_path = g_find_program_in_path ("efibootmgr"); + efibootmgr_path = fu_common_find_program_in_path ("efibootmgr", NULL); if (efibootmgr_path != NULL) { if (!g_spawn_command_line_sync ("efibootmgr -v", &boot_variables, NULL, NULL, error)) diff --git a/src/fu-common.c b/src/fu-common.c index 172da817d..218983505 100644 --- a/src/fu-common.c +++ b/src/fu-common.c @@ -349,6 +349,47 @@ fu_common_add_argv (GPtrArray *argv, const gchar *fmt, ...) g_ptr_array_add (argv, g_strdup (split[i])); } +gchar * +fu_common_find_program_in_path (const gchar *basename, GError **error) +{ + gchar *fn = g_find_program_in_path (basename); + if (fn == NULL) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "missing executable %s in PATH", + basename); + return NULL; + } + return fn; +} + +static gboolean +fu_common_test_namespace_support (GError **error) +{ + /* test if CONFIG_USER_NS is valid */ + if (!g_file_test ("/proc/self/ns/user", G_FILE_TEST_IS_SYMLINK)) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "missing CONFIG_USER_NS in kernel"); + return FALSE; + } + if (g_file_test ("/proc/sys/kernel/unprivileged_userns_clone", G_FILE_TEST_EXISTS)) { + g_autofree gchar *clone = NULL; + if (!g_file_get_contents ("/proc/sys/kernel/unprivileged_userns_clone", &clone, NULL, error)) + return FALSE; + if (g_ascii_strtoll (clone, NULL, 10) == 0) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "unprivileged user namespace clones disabled by distro"); + return FALSE; + } + } + return TRUE; +} + /** * fu_common_firmware_builder: * @bytes: The data to use @@ -391,35 +432,13 @@ fu_common_firmware_builder (GBytes *bytes, g_return_val_if_fail (error == NULL || *error == NULL, NULL); /* find bwrap in the path */ - bwrap_fn = g_find_program_in_path ("bwrap"); - if (bwrap_fn == NULL) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "missing executable bwrap in PATH"); + bwrap_fn = fu_common_find_program_in_path ("bwrap", error); + if (bwrap_fn == NULL) return NULL; - } /* test if CONFIG_USER_NS is valid */ - if (!g_file_test ("/proc/self/ns/user", G_FILE_TEST_IS_SYMLINK)) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "missing CONFIG_USER_NS in kernel"); + if (!fu_common_test_namespace_support (error)) return NULL; - } - if (g_file_test ("/proc/sys/kernel/unprivileged_userns_clone", G_FILE_TEST_EXISTS)) { - g_autofree gchar *clone = NULL; - if (!g_file_get_contents ("/proc/sys/kernel/unprivileged_userns_clone", &clone, NULL, error)) - return NULL; - if (g_ascii_strtoll (clone, NULL, 10) == 0) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "unprivileged user namespace clones disabled by distro"); - return NULL; - } - } /* untar file to temp location */ tmpdir = g_dir_make_tmp ("fwupd-gen-XXXXXX", error); diff --git a/src/fu-common.h b/src/fu-common.h index 7b6337a54..134ab384e 100644 --- a/src/fu-common.h +++ b/src/fu-common.h @@ -62,6 +62,8 @@ GBytes *fu_common_firmware_builder (GBytes *bytes, GError **error); GError *fu_common_error_array_get_best (GPtrArray *errors); guint64 fu_common_strtoull (const gchar *str); +gchar *fu_common_find_program_in_path (const gchar *basename, + GError **error); typedef guint FuEndianType;