mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-06 21:47:09 +00:00
trivial: move kernel version check into common library code
This will be used by more than one plugin in an upcoming commit.
This commit is contained in:
parent
4554eaa688
commit
3a48af58c2
@ -21,6 +21,10 @@
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTSNAME_H
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBARCHIVE
|
||||
#include <archive_entry.h>
|
||||
#include <archive.h>
|
||||
@ -34,6 +38,7 @@
|
||||
#include "fwupd-error.h"
|
||||
|
||||
#include "fu-common-private.h"
|
||||
#include "fu-common-version.h"
|
||||
#include "fu-firmware.h"
|
||||
#include "fu-volume-private.h"
|
||||
|
||||
@ -2569,6 +2574,54 @@ fu_common_kernel_locked_down (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_common_check_kernel_version :
|
||||
* @minimum_kernel: (not nullable): The minimum kernel version to check against
|
||||
* @error: (nullable): optional return location for an error
|
||||
*
|
||||
* Determines if the system is running at least a certain required kernel version
|
||||
*
|
||||
* Since: 1.6.2
|
||||
**/
|
||||
gboolean
|
||||
fu_common_check_kernel_version (const gchar *minimum_kernel, GError **error)
|
||||
{
|
||||
#ifdef HAVE_UTSNAME_H
|
||||
struct utsname name_tmp;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
g_return_val_if_fail (minimum_kernel == NULL, FALSE);
|
||||
|
||||
memset (&name_tmp, 0, sizeof(struct utsname));
|
||||
if (uname (&name_tmp) < 0) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"failed to read kernel version");
|
||||
return FALSE;
|
||||
}
|
||||
if (fu_common_vercmp_full (name_tmp.release,
|
||||
minimum_kernel,
|
||||
FWUPD_VERSION_FORMAT_TRIPLET) < 0) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"kernel %s doesn't meet minimum %s",
|
||||
name_tmp.release, minimum_kernel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
#else
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"platform doesn't support checking for minimum Linux kernel");
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_common_cpuid:
|
||||
* @leaf: the CPUID level, now called the 'leaf' by Intel
|
||||
|
@ -371,6 +371,8 @@ gchar *fu_common_strsafe (const gchar *str,
|
||||
gchar *fu_common_strjoin_array (const gchar *separator,
|
||||
GPtrArray *array);
|
||||
gboolean fu_common_kernel_locked_down (void);
|
||||
gboolean fu_common_check_kernel_version (const gchar *minimum_kernel,
|
||||
GError **error);
|
||||
gboolean fu_common_cpuid (guint32 leaf,
|
||||
guint32 *eax,
|
||||
guint32 *ebx,
|
||||
|
@ -815,3 +815,9 @@ LIBFWUPDPLUGIN_1.6.1 {
|
||||
fu_version_string;
|
||||
local: *;
|
||||
} LIBFWUPDPLUGIN_1.6.0;
|
||||
|
||||
LIBFWUPDPLUGIN_1.6.2 {
|
||||
global:
|
||||
fu_common_check_kernel_version;
|
||||
local: *;
|
||||
} LIBFWUPDPLUGIN_1.6.1;
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <fwupdplugin.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "fu-thunderbolt-device.h"
|
||||
#include "fu-thunderbolt-firmware.h"
|
||||
@ -17,33 +16,13 @@ static gboolean
|
||||
fu_plugin_thunderbolt_safe_kernel (FuPlugin *plugin, GError **error)
|
||||
{
|
||||
g_autofree gchar *minimum_kernel = NULL;
|
||||
struct utsname name_tmp;
|
||||
|
||||
memset (&name_tmp, 0, sizeof(struct utsname));
|
||||
if (uname (&name_tmp) < 0) {
|
||||
g_debug ("Failed to read current kernel version");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
minimum_kernel = fu_plugin_get_config_value (plugin, "MinimumKernelVersion");
|
||||
if (minimum_kernel == NULL) {
|
||||
g_debug ("Ignoring kernel safety checks");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (fu_common_vercmp_full (name_tmp.release,
|
||||
minimum_kernel,
|
||||
FWUPD_VERSION_FORMAT_TRIPLET) < 0) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"kernel %s may not have full Thunderbolt support",
|
||||
name_tmp.release);
|
||||
return FALSE;
|
||||
}
|
||||
g_debug ("Using kernel %s (minimum %s)", name_tmp.release, minimum_kernel);
|
||||
|
||||
return TRUE;
|
||||
return fu_common_check_kernel_version (minimum_kernel, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
Loading…
Reference in New Issue
Block a user