diff --git a/docs/env.md b/docs/env.md index b554da2f0..9b4ee4942 100644 --- a/docs/env.md +++ b/docs/env.md @@ -20,6 +20,10 @@ with a non-standard filesystem layout. * standard glibc variables like `LANG` are also honored for CLI tools that are translated * libcurl respects the session proxy, e.g. `http_proxy`, `all_proxy`, `sftp_proxy` and `no_proxy` +## daemon + +* `FWUPD_MACHINE_KIND` can be used to override the detected machine type, e.g. `physical`, `virtual`, or `container` + ## Self Tests * `CI_NETWORK` if CI is running with network access diff --git a/src/fu-main.c b/src/fu-main.c index cacb54e2f..80c5f67a5 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -54,6 +54,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(PolkitSubject, g_object_unref) #endif /* HAVE_POLKIT */ typedef enum { + FU_MAIN_MACHINE_KIND_UNKNOWN, FU_MAIN_MACHINE_KIND_PHYSICAL, FU_MAIN_MACHINE_KIND_VIRTUAL, FU_MAIN_MACHINE_KIND_CONTAINER, @@ -85,6 +86,18 @@ typedef struct { FuMainMachineKind machine_kind; } FuMainPrivate; +static FuMainMachineKind +fu_main_machine_kind_from_string(const gchar *kind) +{ + if (g_strcmp0(kind, "physical") == 0) + return FU_MAIN_MACHINE_KIND_PHYSICAL; + if (g_strcmp0(kind, "virtual") == 0) + return FU_MAIN_MACHINE_KIND_VIRTUAL; + if (g_strcmp0(kind, "container") == 0) + return FU_MAIN_MACHINE_KIND_CONTAINER; + return FU_MAIN_MACHINE_KIND_UNKNOWN; +} + static gboolean fu_main_sigterm_cb(gpointer user_data) { @@ -2187,6 +2200,7 @@ main(int argc, char *argv[]) { gboolean immediate_exit = FALSE; gboolean timed_exit = FALSE; + const gchar *machine_kind = g_getenv("FWUPD_MACHINE_KIND"); const gchar *socket_filename = g_getenv("FWUPD_DBUS_SOCKET"); const GOptionEntry options[] = { {"timed-exit", @@ -2237,6 +2251,23 @@ main(int argc, char *argv[]) (GDestroyNotify)fu_main_sender_item_free); priv->loop = g_main_loop_new(NULL, FALSE); + /* allow overriding for development */ + if (machine_kind != NULL) { + priv->machine_kind = fu_main_machine_kind_from_string(machine_kind); + if (priv->machine_kind == FU_MAIN_MACHINE_KIND_UNKNOWN) { + g_printerr("Invalid machine kind specified: %s\n", machine_kind); + return EXIT_FAILURE; + } + } else { + if (fu_main_is_hypervisor()) { + priv->machine_kind = FU_MAIN_MACHINE_KIND_VIRTUAL; + } else if (fu_main_is_container()) { + priv->machine_kind = FU_MAIN_MACHINE_KIND_CONTAINER; + } else { + priv->machine_kind = FU_MAIN_MACHINE_KIND_PHYSICAL; + } + } + /* load engine */ priv->engine = fu_engine_new(FU_APP_FLAGS_NONE); g_signal_connect(FU_ENGINE(priv->engine), @@ -2306,13 +2337,6 @@ main(int argc, char *argv[]) } #endif - /* are we a VM? */ - if (fu_main_is_hypervisor()) { - priv->machine_kind = FU_MAIN_MACHINE_KIND_VIRTUAL; - } else if (fu_main_is_container()) { - priv->machine_kind = FU_MAIN_MACHINE_KIND_CONTAINER; - } - /* own the object */ if (socket_filename != NULL) { g_autofree gchar *address = g_strdup_printf("unix:path=%s", socket_filename);