From a45994cb4a56ba0044a40ec99b8da5559b0a01fe Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Wed, 18 Sep 2019 08:26:14 +0100 Subject: [PATCH] Fall back to /var/lib/dbus/machine-id when required Fixes https://github.com/fwupd/fwupd/issues/1365 --- libfwupd/fwupd-common.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libfwupd/fwupd-common.c b/libfwupd/fwupd-common.c index 8bd5fff38..078b42b78 100644 --- a/libfwupd/fwupd-common.c +++ b/libfwupd/fwupd-common.c @@ -313,12 +313,31 @@ fwupd_build_user_agent (const gchar *package_name, const gchar *package_version) gchar * 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_autoptr(GChecksum) csum = NULL; gsize sz = 0; - /* this has to exist */ - if (!g_file_get_contents ("/etc/machine-id", &buf, &sz, error)) + /* one of these has to exist */ + fns[0] = g_build_filename (SYSCONFDIR, "machine-id", NULL); + fns[1] = g_build_filename (LOCALSTATEDIR, "lib", "dbus", "machine-id", NULL); + fns[2] = g_strdup ("/etc/machine-id"); + fns[3] = g_strdup ("/var/lib/dbus/machine-id"); + for (guint i = 0; fns[i] != NULL; i++) { + if (g_file_test (fns[i], G_FILE_TEST_EXISTS)) { + fn = fns[i]; + break; + } + } + if (fn == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_READ, + "The machine-id is not present"); + return NULL; + } + if (!g_file_get_contents (fn, &buf, &sz, error)) return NULL; if (sz == 0) { g_set_error_literal (error,