mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-07 22:57:14 +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);
|
FuPluginData *data = fu_plugin_get_data (plugin);
|
||||||
GPtrArray *hwids;
|
GPtrArray *hwids;
|
||||||
|
g_autoptr(GError) error_local = NULL;
|
||||||
|
|
||||||
/* we need flashrom from the host system */
|
/* 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 */
|
/* search for devices */
|
||||||
hwids = fu_plugin_get_hwids (plugin);
|
hwids = fu_plugin_get_hwids (plugin);
|
||||||
@ -70,7 +71,7 @@ fu_plugin_startup (FuPlugin *plugin, GError **error)
|
|||||||
if (data->flashrom_fn != NULL) {
|
if (data->flashrom_fn != NULL) {
|
||||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE);
|
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE);
|
||||||
} else {
|
} 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_add_guid (dev, guid);
|
||||||
fu_device_set_name (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME));
|
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;
|
return FALSE;
|
||||||
|
|
||||||
/* record boot information to system log for future debugging */
|
/* 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 (efibootmgr_path != NULL) {
|
||||||
if (!g_spawn_command_line_sync ("efibootmgr -v",
|
if (!g_spawn_command_line_sync ("efibootmgr -v",
|
||||||
&boot_variables, NULL, NULL, error))
|
&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]));
|
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:
|
* fu_common_firmware_builder:
|
||||||
* @bytes: The data to use
|
* @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);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
/* find bwrap in the path */
|
/* find bwrap in the path */
|
||||||
bwrap_fn = g_find_program_in_path ("bwrap");
|
bwrap_fn = fu_common_find_program_in_path ("bwrap", error);
|
||||||
if (bwrap_fn == NULL) {
|
if (bwrap_fn == NULL)
|
||||||
g_set_error (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_NOT_SUPPORTED,
|
|
||||||
"missing executable bwrap in PATH");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* test if CONFIG_USER_NS is valid */
|
/* test if CONFIG_USER_NS is valid */
|
||||||
if (!g_file_test ("/proc/self/ns/user", G_FILE_TEST_IS_SYMLINK)) {
|
if (!fu_common_test_namespace_support (error))
|
||||||
g_set_error (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_NOT_SUPPORTED,
|
|
||||||
"missing CONFIG_USER_NS in kernel");
|
|
||||||
return NULL;
|
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 */
|
/* untar file to temp location */
|
||||||
tmpdir = g_dir_make_tmp ("fwupd-gen-XXXXXX", error);
|
tmpdir = g_dir_make_tmp ("fwupd-gen-XXXXXX", error);
|
||||||
|
@ -62,6 +62,8 @@ GBytes *fu_common_firmware_builder (GBytes *bytes,
|
|||||||
GError **error);
|
GError **error);
|
||||||
GError *fu_common_error_array_get_best (GPtrArray *errors);
|
GError *fu_common_error_array_get_best (GPtrArray *errors);
|
||||||
guint64 fu_common_strtoull (const gchar *str);
|
guint64 fu_common_strtoull (const gchar *str);
|
||||||
|
gchar *fu_common_find_program_in_path (const gchar *basename,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
typedef guint FuEndianType;
|
typedef guint FuEndianType;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user