From afdba37644966adeacac492054e1a64e1e9e9ca8 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sat, 23 Nov 2019 12:57:35 +0000 Subject: [PATCH] trivial: Set the offline trigger using an environment variable This allows us to build a object that does not have a custom FU_OFFLINE_DESTDIR. --- plugins/dell/meson.build | 1 - plugins/optionrom/meson.build | 1 - plugins/synapticsmst/meson.build | 1 - plugins/thunderbolt/meson.build | 1 - src/fu-common.c | 5 +++++ src/fu-common.h | 2 ++ src/fu-offline.c | 5 +++-- src/fu-plugin-private.h | 2 -- src/fu-plugin.c | 14 ++++++++------ src/fu-self-test.c | 1 + src/meson.build | 10 ---------- 11 files changed, 19 insertions(+), 24 deletions(-) diff --git a/plugins/dell/meson.build b/plugins/dell/meson.build index 171154f81..5ab20e309 100644 --- a/plugins/dell/meson.build +++ b/plugins/dell/meson.build @@ -34,7 +34,6 @@ shared_module('fu_plugin_dell', if get_option('tests') testdatadir = join_paths(meson.current_source_dir(), 'tests') cargs += '-DTESTDATADIR="' + testdatadir + '"' - cargs += '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"' cargs += '-DPLUGINBUILDDIR="' + meson.current_build_dir() + '"' e = executable( 'dell-self-test', diff --git a/plugins/optionrom/meson.build b/plugins/optionrom/meson.build index 13dc22869..96dcc5f97 100644 --- a/plugins/optionrom/meson.build +++ b/plugins/optionrom/meson.build @@ -50,7 +50,6 @@ executable( ) if get_option('tests') - cargs += '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"' cargs += '-DPLUGINBUILDDIR="' + meson.current_build_dir() + '"' testdatadir = join_paths(meson.current_source_dir(), 'tests') cargs += '-DTESTDATADIR="' + testdatadir + '"' diff --git a/plugins/synapticsmst/meson.build b/plugins/synapticsmst/meson.build index eb2723737..05844d779 100644 --- a/plugins/synapticsmst/meson.build +++ b/plugins/synapticsmst/meson.build @@ -31,7 +31,6 @@ shared_module('fu_plugin_synapticsmst', ) if get_option('tests') - cargs += '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"' cargs += '-DPLUGINBUILDDIR="' + meson.current_build_dir() + '"' cargs += '-DSOURCEDIR="' + meson.current_source_dir() + '"' e = executable( diff --git a/plugins/thunderbolt/meson.build b/plugins/thunderbolt/meson.build index 42718abf6..87c6c8d11 100644 --- a/plugins/thunderbolt/meson.build +++ b/plugins/thunderbolt/meson.build @@ -50,7 +50,6 @@ install_data(['thunderbolt.conf'], ) # we use functions from 2.52 in the tests if get_option('tests') and umockdev.found() and gio.version().version_compare('>= 2.52') - cargs += '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"' cargs += '-DPLUGINBUILDDIR="' + meson.current_build_dir() + '"' e = executable( 'thunderbolt-self-test', diff --git a/src/fu-common.c b/src/fu-common.c index c72953712..99a5035be 100644 --- a/src/fu-common.c +++ b/src/fu-common.c @@ -1044,6 +1044,11 @@ fu_common_get_path (FuPathKind path_kind) return g_build_filename (tmp, NULL); basedir = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR); return g_build_filename (basedir, "cache", PACKAGE_NAME, NULL); + case FU_PATH_KIND_OFFLINE_TRIGGER: + tmp = g_getenv ("FWUPD_OFFLINE_TRIGGER"); + if (tmp != NULL) + return g_strdup (tmp); + return g_strdup ("/system-update"); case FU_PATH_KIND_POLKIT_ACTIONS: #ifdef POLKIT_ACTIONDIR return g_strdup (POLKIT_ACTIONDIR); diff --git a/src/fu-common.h b/src/fu-common.h index 7c1a0c89b..5bc1b3421 100644 --- a/src/fu-common.h +++ b/src/fu-common.h @@ -54,6 +54,7 @@ typedef guint FuEndianType; * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers) * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm) * @FU_PATH_KIND_POLKIT_ACTIONS: The directory for policy kit actions (IE /usr/share/polkit-1/actions/) + * @FU_PATH_KIND_OFFLINE_TRIGGER: The file for the offline trigger (IE /system-update) * * Path types to use when dynamically determining a path at runtime **/ @@ -70,6 +71,7 @@ typedef enum { FU_PATH_KIND_SYSFSDIR_DRIVERS, FU_PATH_KIND_SYSFSDIR_TPM, FU_PATH_KIND_POLKIT_ACTIONS, + FU_PATH_KIND_OFFLINE_TRIGGER, /*< private >*/ FU_PATH_KIND_LAST } FuPathKind; diff --git a/src/fu-offline.c b/src/fu-offline.c index 6c053a3a9..e84fb24c6 100644 --- a/src/fu-offline.c +++ b/src/fu-offline.c @@ -141,6 +141,7 @@ main (int argc, char *argv[]) guint cnt = 0; g_autofree gchar *link = NULL; g_autofree gchar *target = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); g_autoptr(FuHistory) history = NULL; g_autoptr(FwupdClient) client = NULL; g_autoptr(GError) error = NULL; @@ -154,14 +155,14 @@ main (int argc, char *argv[]) textdomain (GETTEXT_PACKAGE); /* verify this is pointing to our cache */ - link = g_file_read_link (FU_OFFLINE_TRIGGER_FILENAME, NULL); + link = g_file_read_link (trigger, NULL); if (link == NULL) return EXIT_SUCCESS; if (g_strcmp0 (link, target) != 0) return EXIT_SUCCESS; /* do this first to avoid a loop if this tool segfaults */ - g_unlink (FU_OFFLINE_TRIGGER_FILENAME); + g_unlink (trigger); /* ensure root user */ #ifdef HAVE_GETUID diff --git a/src/fu-plugin-private.h b/src/fu-plugin-private.h index 6d3ec43a1..7a0c85af7 100644 --- a/src/fu-plugin-private.h +++ b/src/fu-plugin-private.h @@ -10,8 +10,6 @@ #include "fu-plugin.h" #include "fu-smbios.h" -#define FU_OFFLINE_TRIGGER_FILENAME FU_OFFLINE_DESTDIR "/system-update" - FuPlugin *fu_plugin_new (void); gboolean fu_plugin_is_open (FuPlugin *self); void fu_plugin_set_usb_context (FuPlugin *self, diff --git a/src/fu-plugin.c b/src/fu-plugin.c index 9da9e847e..cff8cf735 100644 --- a/src/fu-plugin.c +++ b/src/fu-plugin.c @@ -1011,12 +1011,13 @@ fu_plugin_runner_startup (FuPlugin *self, GError **error) static gboolean fu_plugin_runner_offline_invalidate (GError **error) { + g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); g_autoptr(GError) error_local = NULL; g_autoptr(GFile) file1 = NULL; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - file1 = g_file_new_for_path (FU_OFFLINE_TRIGGER_FILENAME); + file1 = g_file_new_for_path (trigger); if (!g_file_query_exists (file1, NULL)) return TRUE; if (!g_file_delete (file1, NULL, &error_local)) { @@ -1024,7 +1025,7 @@ fu_plugin_runner_offline_invalidate (GError **error) FWUPD_ERROR, FWUPD_ERROR_INTERNAL, "Cannot delete %s: %s", - FU_OFFLINE_TRIGGER_FILENAME, + trigger, error_local->message); return FALSE; } @@ -1037,25 +1038,26 @@ fu_plugin_runner_offline_setup (GError **error) gint rc; g_autofree gchar *filename = NULL; g_autofree gchar *symlink_target = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *trigger = fu_common_get_path (FU_PATH_KIND_OFFLINE_TRIGGER); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* does already exist */ - filename = fu_common_realpath (FU_OFFLINE_TRIGGER_FILENAME, NULL); + filename = fu_common_realpath (trigger, NULL); if (g_strcmp0 (filename, symlink_target) == 0) { g_debug ("%s already points to %s, skipping creation", - FU_OFFLINE_TRIGGER_FILENAME, symlink_target); + trigger, symlink_target); return TRUE; } /* create symlink for the systemd-system-update-generator */ - rc = symlink (symlink_target, FU_OFFLINE_TRIGGER_FILENAME); + rc = symlink (symlink_target, trigger); if (rc < 0) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL, "Failed to create symlink %s to %s: %s", - FU_OFFLINE_TRIGGER_FILENAME, + trigger, "/var/lib", strerror (errno)); return FALSE; } diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 0d927c8bc..488555564 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -4187,6 +4187,7 @@ main (int argc, char **argv) g_setenv ("FWUPD_PLUGINDIR", TESTDATADIR_SRC, TRUE); g_setenv ("FWUPD_SYSCONFDIR", TESTDATADIR_SRC, TRUE); g_setenv ("FWUPD_SYSFSFWDIR", TESTDATADIR_SRC, TRUE); + g_setenv ("FWUPD_OFFLINE_TRIGGER", "/tmp/fwupd-self-test/system-update", TRUE); g_setenv ("FWUPD_LOCALSTATEDIR", "/tmp/fwupd-self-test/var", TRUE); /* ensure empty tree */ diff --git a/src/meson.build b/src/meson.build index 6b37c5b45..5c3020cf2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -106,9 +106,6 @@ fwupdmgr = executable( fwupd, libfwupdprivate, ], - c_args : [ - '-DFU_OFFLINE_DESTDIR=""', - ], install : true, install_dir : bindir ) @@ -164,9 +161,6 @@ fwupdagent = executable( fwupd, libfwupdprivate, ], - c_args : [ - '-DFU_OFFLINE_DESTDIR=""', - ], install : true, install_dir : join_paths(libexecdir, 'fwupd') ) @@ -230,9 +224,6 @@ fwupdtool = executable( fwupd, libfwupdprivate, ], - c_args : [ - '-DFU_OFFLINE_DESTDIR=""', - ], install : true, install_dir : join_paths(libexecdir, 'fwupd') ) @@ -359,7 +350,6 @@ if get_option('tests') '-DTESTDATADIR_DST="' + testdatadir_dst + '"', '-DTESTDATADIR="' + testdatadir_src + ':' + testdatadir_dst + '"', '-DPLUGINBUILDDIR="' + pluginbuilddir + '"', - '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"', ], ) test('fu-self-test', e, is_parallel:false, timeout:180)