mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-03 16:25:10 +00:00
trivial: Refactor out functionality from a mega-method
This commit is contained in:
parent
50d6bd10bd
commit
22367e7948
@ -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));
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user