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 <campello@chromium.org>, many thanks.
This commit is contained in:
Richard Hughes 2022-03-09 09:15:52 +00:00 committed by Daniel Campello
parent 6fdae41ae0
commit 91512925a0
2 changed files with 17 additions and 4 deletions

View File

@ -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;
}
}

6
src/tests/os-release Normal file
View File

@ -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