diff --git a/steam-runtime-tools/os.c b/steam-runtime-tools/os.c index 4fba109c5e67cab14c780e953d875696d3e379ba..0d9f115529561cb931b724057e439669c737b77d 100644 --- a/steam-runtime-tools/os.c +++ b/steam-runtime-tools/os.c @@ -48,10 +48,17 @@ _srt_os_release_init (SrtOsRelease *self) self->populated = FALSE; } -static const char * const os_release_paths[] = +static const struct { - "/etc/os-release", - "/usr/lib/os-release" + const char *path; + gboolean only_in_run_host; +} +os_release_paths[] = +{ + { "/etc/os-release", FALSE }, + { "/usr/lib/os-release", FALSE }, + /* https://github.com/flatpak/flatpak/pull/3733 */ + { "/os-release", TRUE } }; static void @@ -150,23 +157,24 @@ _srt_os_release_populate (SrtOsRelease *self, for (i = 0; i < G_N_ELEMENTS (os_release_paths); i++) { + const char *path = os_release_paths[i].path; + gboolean only_in_run_host = os_release_paths[i].only_in_run_host; gchar *built_path = NULL; gchar *contents = NULL; - const char *path = NULL; char *beginning_of_line; GError *local_error = NULL; gsize len; gsize j; + if (only_in_run_host + && (sysroot == NULL || !g_str_has_suffix (sysroot, "/run/host"))) + continue; + if (sysroot != NULL) { - built_path = g_build_filename (sysroot, os_release_paths[i], NULL); + built_path = g_build_filename (sysroot, path, NULL); path = built_path; } - else - { - path = os_release_paths[i]; - } if (!g_file_get_contents (path, &contents, &len, &local_error)) { diff --git a/tests/generate-sysroots.py b/tests/generate-sysroots.py index 2cdb98f4f276abec3f8130d052f7a73c18d6aada..b65a5ca94b82c31388e2c3d1735386537c88150a 100755 --- a/tests/generate-sysroots.py +++ b/tests/generate-sysroots.py @@ -253,8 +253,12 @@ BUG_REPORT_URL="https://bugs.debian.org/" with open('debian10/run/systemd/container', 'w') as writer: writer.write('whatever\n') -with open('debian-unstable/etc/os-release', 'w') as writer: - writer.write('''\ +for name in ( + 'debian-unstable/etc/os-release', + 'flatpak-example/run/host/os-release', +): + with open(name, 'w') as writer: + writer.write('''\ PRETTY_NAME="Debian GNU/Linux bullseye/sid" NAME="Debian GNU/Linux" ID=debian diff --git a/tests/system-info.c b/tests/system-info.c index 127a708e58ac85fc5c301e4a94f3c8b1417faf89..99a56453ebc554086c906391111e8bfae48e7c82 100644 --- a/tests/system-info.c +++ b/tests/system-info.c @@ -1344,12 +1344,13 @@ static void os_debian_unstable (Fixture *f, gconstpointer context) { + const char *sysroot_name = context; SrtSystemInfo *info; gchar **strv; gchar *sysroot; gchar *s; - sysroot = g_build_filename (f->sysroots, "debian-unstable", NULL); + sysroot = g_build_filename (f->sysroots, sysroot_name, NULL); info = srt_system_info_new (NULL); srt_system_info_set_sysroot (info, sysroot); @@ -3231,7 +3232,11 @@ main (int argc, g_test_add ("/system-info/os/debian10", Fixture, NULL, setup, os_debian10, teardown); - g_test_add ("/system-info/os/debian-unstable", Fixture, NULL, + g_test_add ("/system-info/os/debian-unstable", Fixture, + "debian-unstable", + setup, os_debian_unstable, teardown); + g_test_add ("/system-info/os/flatpak-on-debian-unstable", Fixture, + "flatpak-example/run/host", setup, os_debian_unstable, teardown); g_test_add ("/system-info/os/steamrt", Fixture, NULL, setup, os_steamrt, teardown);