From 91512925a0e4e86b95b6e6f81471d690c737c6ef Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Wed, 9 Mar 2022 09:15:52 +0000 Subject: [PATCH] Check for os-release on FWUPD_SYSCONFDIR Change-Id: I391eabfb1ef6eadbad100273445794172b2cb1fd Fixes https://github.com/fwupd/fwupd/issues/4366 Based on a patch by Daniel Campello , many thanks. --- libfwupd/fwupd-common.c | 15 +++++++++++---- src/tests/os-release | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/tests/os-release diff --git a/libfwupd/fwupd-common.c b/libfwupd/fwupd-common.c index 3a21792ba..825846be6 100644 --- a/libfwupd/fwupd-common.c +++ b/libfwupd/fwupd-common.c @@ -154,17 +154,24 @@ GHashTable * fwupd_get_os_release(GError **error) { const gchar *filename = NULL; - const gchar *paths[] = {"/etc/os-release", "/usr/lib/os-release", NULL}; + const gchar *sysconfdir = g_getenv("FWUPD_SYSCONFDIR"); g_autofree gchar *buf = NULL; g_auto(GStrv) lines = NULL; g_autoptr(GHashTable) hash = NULL; + g_autoptr(GPtrArray) paths = g_ptr_array_new_with_free_func(g_free); g_return_val_if_fail(error == NULL || *error == NULL, NULL); /* find the correct file */ - for (guint i = 0; paths[i] != NULL; i++) { - if (g_file_test(paths[i], G_FILE_TEST_EXISTS)) { - filename = paths[i]; + if (sysconfdir != NULL) + g_ptr_array_add(paths, g_build_filename(sysconfdir, "os-release", NULL)); + if (g_strcmp0(sysconfdir, "/etc") != 0) + g_ptr_array_add(paths, g_strdup("/etc/os-release")); + g_ptr_array_add(paths, g_strdup("/usr/lib/os-release")); + for (guint i = 0; i < paths->len; i++) { + const gchar *path = g_ptr_array_index(paths, i); + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + filename = path; break; } } diff --git a/src/tests/os-release b/src/tests/os-release new file mode 100644 index 000000000..a156658c9 --- /dev/null +++ b/src/tests/os-release @@ -0,0 +1,6 @@ +ID_LIKE=chromiumos +GOOGLE_CRASH_ID=ChromeOS +NAME=Chrome OS +ID=chromeos +HOME_URL=https://www.chromium.org/chromium-os +BUG_REPORT_URL=https://crbug.com/new