From 508bb99f82fc3e973fd9edea4b20abdc1d9bbc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norbert=20Kami=C5=84ski?= Date: Mon, 8 Mar 2021 11:38:43 +0100 Subject: [PATCH] fwupd port for BSD distros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Norbert KamiƄski --- libfwupd/fwupd-common.c | 35 +++++++++++++++++++++------------ libfwupd/meson.build | 1 + libfwupdplugin/fu-common.c | 2 +- libfwupdplugin/fu-efivar.c | 12 +++++------ libfwupdplugin/fu-udev-device.c | 2 +- libfwupdplugin/meson.build | 1 + meson.build | 2 +- src/fu-engine.c | 2 +- src/fu-main.c | 2 ++ src/fu-self-test.c | 2 +- 10 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libfwupd/fwupd-common.c b/libfwupd/fwupd-common.c index 80602065e77..18666100a4e 100644 --- a/libfwupd/fwupd-common.c +++ b/libfwupd/fwupd-common.c @@ -152,23 +152,14 @@ fwupd_checksum_get_best (GPtrArray *checksums) GHashTable * fwupd_get_os_release (GError **error) { - GHashTable *hash; const gchar *filename = NULL; const gchar *paths[] = { "/etc/os-release", "/usr/lib/os-release", NULL }; g_autofree gchar *buf = NULL; g_auto(GStrv) lines = NULL; + g_autoptr(GHashTable) hash = NULL; g_return_val_if_fail (error == NULL || *error == NULL, NULL); -/* TODO: Read the Windows version */ -#ifdef _WIN32 - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - g_hash_table_insert (hash, - g_strdup("OS"), - g_strdup("Windows")); - return hash; -#endif - /* find the correct file */ for (guint i = 0; paths[i] != NULL; i++) { if (g_file_test (paths[i], G_FILE_TEST_EXISTS)) { @@ -176,7 +167,25 @@ fwupd_get_os_release (GError **error) break; } } + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (filename == NULL) { +#if defined(_WIN32) + /* TODO: Read the Windows version */ + g_hash_table_insert (hash, + g_strdup ("OS"), + g_strdup ("Windows")); +#elif defined(__NetBSD__) + g_hash_table_insert (hash, + g_strdup ("OS"), + g_strdup ("NetBSD")); +#elif defined(__OpenBSD__) + g_hash_table_insert (hash, + g_strdup ("OS"), + g_strdup ("OpenBSD")); +#endif + if (g_hash_table_size (hash) > 0) + return g_steal_pointer (&hash); g_set_error_literal (error, FWUPD_ERROR, FWUPD_ERROR_READ, @@ -187,7 +196,6 @@ fwupd_get_os_release (GError **error) /* load each line */ if (!g_file_get_contents (filename, &buf, NULL, error)) return NULL; - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); lines = g_strsplit (buf, "\n", -1); for (guint i = 0; lines[i] != NULL; i++) { gsize len, off = 0; @@ -210,7 +218,7 @@ fwupd_get_os_release (GError **error) g_strdup (split[0]), g_strndup (split[1] + off, len)); } - return hash; + return g_steal_pointer (&hash); } static gchar * @@ -346,7 +354,7 @@ fwupd_build_machine_id (const gchar *salt, GError **error) { const gchar *fn = NULL; g_autofree gchar *buf = NULL; - g_auto(GStrv) fns = g_new0 (gchar *, 5); + g_auto(GStrv) fns = g_new0 (gchar *, 6); g_autoptr(GChecksum) csum = NULL; gsize sz = 0; @@ -358,6 +366,7 @@ fwupd_build_machine_id (const gchar *salt, GError **error) fns[1] = g_build_filename (FWUPD_LOCALSTATEDIR, "lib", "dbus", "machine-id", NULL); fns[2] = g_strdup ("/etc/machine-id"); fns[3] = g_strdup ("/var/lib/dbus/machine-id"); + fns[4] = g_strdup ("/var/db/dbus/machine-id"); for (guint i = 0; fns[i] != NULL; i++) { if (g_file_test (fns[i], G_FILE_TEST_EXISTS)) { fn = fns[i]; diff --git a/libfwupd/meson.build b/libfwupd/meson.build index 5f2350b19f9..19885095514 100644 --- a/libfwupd/meson.build +++ b/libfwupd/meson.build @@ -154,6 +154,7 @@ if get_option('introspection') input: fwupd_gir[0], output: 'fwupd.map', command: [ + python3, join_paths(meson.source_root(), 'contrib', 'generate-version-script.py'), 'LIBFWUPD', '@INPUT@', diff --git a/libfwupdplugin/fu-common.c b/libfwupdplugin/fu-common.c index c08524f2c6a..58b41bc7926 100644 --- a/libfwupdplugin/fu-common.c +++ b/libfwupdplugin/fu-common.c @@ -2573,7 +2573,7 @@ fu_byte_array_align_up (GByteArray *array, guint8 alignment, guint8 data) gboolean fu_common_kernel_locked_down (void) { -#ifndef _WIN32 +#ifdef __linux__ gsize len = 0; g_autofree gchar *dir = fu_common_get_path (FU_PATH_KIND_SYSFSDIR_SECURITY); g_autofree gchar *fname = g_build_filename (dir, "lockdown", NULL); diff --git a/libfwupdplugin/fu-efivar.c b/libfwupdplugin/fu-efivar.c index d2f025fb0bb..6c2083ee005 100644 --- a/libfwupdplugin/fu-efivar.c +++ b/libfwupdplugin/fu-efivar.c @@ -10,7 +10,7 @@ #include #include #include -#ifndef _WIN32 +#ifdef __linux__ #include #include #include @@ -49,7 +49,7 @@ fu_efivar_get_filename (const gchar *guid, const gchar *name) gboolean fu_efivar_supported (GError **error) { -#ifndef _WIN32 +#ifdef __linux__ g_autofree gchar *efivardir = fu_efivar_get_path (); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (!g_file_test (efivardir, G_FILE_TEST_IS_DIR)) { @@ -71,7 +71,7 @@ fu_efivar_supported (GError **error) #endif } -#ifndef _WIN32 +#ifdef __linux__ static gboolean fu_efivar_set_immutable_fd (int fd, gboolean value, @@ -135,7 +135,7 @@ fu_efivar_set_immutable (const gchar *fn, gboolean *value_old, GError **error) { -#ifndef _WIN32 +#ifdef __linux__ gint fd; g_autoptr(GInputStream) istr = NULL; @@ -298,7 +298,7 @@ gboolean fu_efivar_get_data (const gchar *guid, const gchar *name, guint8 **data, gsize *data_sz, guint32 *attr, GError **error) { -#ifndef _WIN32 +#ifdef __linux__ gssize attr_sz; gssize data_sz_tmp; guint32 attr_tmp; @@ -546,7 +546,7 @@ gboolean fu_efivar_set_data (const gchar *guid, const gchar *name, const guint8 *data, gsize sz, guint32 attr, GError **error) { -#ifndef _WIN32 +#ifdef __linux__ int fd; int open_wflags; gboolean was_immutable; diff --git a/libfwupdplugin/fu-udev-device.c b/libfwupdplugin/fu-udev-device.c index 6833908480a..472345a2e1c 100644 --- a/libfwupdplugin/fu-udev-device.c +++ b/libfwupdplugin/fu-udev-device.c @@ -1669,7 +1669,7 @@ gboolean fu_udev_device_write_sysfs (FuUdevDevice *self, const gchar *attribute, const gchar *val, GError **error) { -#ifndef _WIN32 +#ifdef __linux__ ssize_t n; int r; int fd; diff --git a/libfwupdplugin/meson.build b/libfwupdplugin/meson.build index 2f588c0b5f6..f6cc7b18b11 100644 --- a/libfwupdplugin/meson.build +++ b/libfwupdplugin/meson.build @@ -220,6 +220,7 @@ if get_option('introspection') and get_option('gusb') input: fwupdplugin_gir[0], output: 'fwupdplugin.map', command: [ + python3, join_paths(meson.source_root(), 'contrib', 'generate-version-script.py'), 'LIBFWUPDPLUGIN', '@INPUT@', diff --git a/meson.build b/meson.build index e7939ef3ebe..0d8c778da98 100644 --- a/meson.build +++ b/meson.build @@ -242,7 +242,7 @@ if build_daemon warning('Polkit is disabled, the daemon will allow ALL client actions') endif udevdir = get_option('udevdir') - if udevdir == '' + if udevdir == '' and host_machine.system() == 'linux' udev = dependency('udev') udevdir = udev.get_pkgconfig_variable('udevdir') endif diff --git a/src/fu-engine.c b/src/fu-engine.c index 04cd26f93f1..19d8f688bc6 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -6358,7 +6358,7 @@ fu_engine_load (FuEngine *self, FuEngineLoadFlags flags, GError **error) guint backend_cnt = 0; g_autoptr(GPtrArray) checksums_approved = NULL; g_autoptr(GPtrArray) checksums_blocked = NULL; -#ifndef _WIN32 +#ifdef __linux__ g_autoptr(GError) error_local = NULL; #endif diff --git a/src/fu-main.c b/src/fu-main.c index 5c65c1f9cfb..ea885e43ca2 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -2041,8 +2041,10 @@ main (int argc, char *argv[]) else if (timed_exit) g_timeout_add_seconds (5, fu_main_timed_exit_cb, priv->loop); +#ifdef __linux__ /* drop heap except one page */ malloc_trim (4096); +#endif /* wait */ g_message ("Daemon ready for requests (locale %s)", g_getenv ("LANG")); diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 575cc8dc388..2bb01b6f9ea 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -583,7 +583,7 @@ fu_engine_requirements_device_func (gconstpointer user_data) " " " bootloader" " vendor-id" -#ifndef _WIN32 +#ifdef __linux__ " org.kernel" #endif " "