Skip to content
Snippets Groups Projects
Commit 82725bfc authored by Simon McVittie's avatar Simon McVittie
Browse files

os: Use pre-opened sysroot fd to read /etc/os-release, etc.

parent 3bfdffbe
No related branches found
No related tags found
1 merge request!139Move resolve-in-sysroot into the shared library
......@@ -46,7 +46,8 @@ typedef struct
G_GNUC_INTERNAL void _srt_os_release_init (SrtOsRelease *self);
G_GNUC_INTERNAL void _srt_os_release_populate (SrtOsRelease *self,
const char *sysroot);
const char *sysroot,
int sysroot_fd);
G_GNUC_INTERNAL void _srt_os_release_clear (SrtOsRelease *self);
void _srt_os_release_populate_from_report (JsonObject *json_obj,
SrtOsRelease *self);
......@@ -141,7 +141,8 @@ do_line (SrtOsRelease *self,
G_GNUC_INTERNAL void
_srt_os_release_populate (SrtOsRelease *self,
const char *sysroot)
const char *sysroot,
int sysroot_fd)
{
gsize i;
......@@ -155,33 +156,28 @@ _srt_os_release_populate (SrtOsRelease *self,
g_return_if_fail (self->variant_id == NULL);
g_return_if_fail (self->version_codename == NULL);
g_return_if_fail (self->version_id == NULL);
g_return_if_fail (sysroot != NULL);
g_return_if_fail (sysroot_fd >= 0);
for (i = 0; i < G_N_ELEMENTS (os_release_paths); i++)
{
g_autoptr(GError) local_error = NULL;
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;
g_autofree gchar *contents = 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")))
&& !g_str_has_suffix (sysroot, "/run/host"))
continue;
if (sysroot != NULL)
if (!_srt_file_get_contents_in_sysroot (sysroot_fd, path,
&contents, &len,
&local_error))
{
built_path = g_build_filename (sysroot, path, NULL);
path = built_path;
}
if (!g_file_get_contents (path, &contents, &len, &local_error))
{
g_debug ("Unable to open %s: %s", path, local_error->message);
g_clear_error (&local_error);
g_free (built_path);
g_debug ("%s", local_error->message);
continue;
}
......@@ -201,9 +197,6 @@ _srt_os_release_populate (SrtOsRelease *self,
/* Collect a possible partial line */
do_line (self, path, beginning_of_line);
g_free (contents);
g_free (built_path);
break;
}
......
......@@ -2100,8 +2100,11 @@ srt_system_info_dup_steam_bin32_path (SrtSystemInfo *self)
static void
ensure_os_cached (SrtSystemInfo *self)
{
if (!self->os_release.populated && !self->immutable_values)
_srt_os_release_populate (&self->os_release, self->sysroot);
if (!self->os_release.populated
&& !self->immutable_values
&& self->sysroot_fd >= 0)
_srt_os_release_populate (&self->os_release, self->sysroot,
self->sysroot_fd);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment