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

pressure-vessel: Share host /etc/hosts, etc., according to a table


We take the same action for each of these files, so let's make the
code more data-driven.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent ae9b8635
No related branches found
No related tags found
1 merge request!232Provide /etc/amd, /var/tmp, /run/host/etc, /run/gfx/etc in container
......@@ -1660,13 +1660,8 @@ bind_runtime_base (PvRuntime *self,
};
static const char * const dont_bind[] =
{
"/etc/group",
"/etc/passwd",
"/etc/host.conf",
"/etc/hosts",
"/etc/localtime",
"/etc/machine-id",
"/etc/resolv.conf",
"/var/cache/ldconfig",
"/var/lib/dbus",
"/var/lib/dhcp",
......@@ -1674,6 +1669,17 @@ bind_runtime_base (PvRuntime *self,
"/var/lib/urandom",
NULL
};
static const char * const from_host[] =
{
/* TODO: Synthesize a passwd with only the user and nobody,
* like Flatpak does? */
"/etc/group",
"/etc/passwd",
"/etc/host.conf",
"/etc/hosts",
"/etc/resolv.conf",
NULL
};
g_autofree gchar *xrd = g_strdup_printf ("/run/user/%ld", (long) geteuid ());
gsize i, j;
const gchar *member;
......@@ -1774,6 +1780,9 @@ bind_runtime_base (PvRuntime *self,
if (g_strv_contains (dont_bind, dest))
continue;
if (g_strv_contains (from_host, dest))
continue;
full = g_build_filename (self->runtime_files,
bind_mutable[i],
member,
......@@ -1859,37 +1868,16 @@ bind_runtime_base (PvRuntime *self,
NULL);
}
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
"/etc/resolv.conf", G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", "/etc/resolv.conf", "/etc/resolv.conf",
NULL);
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
"/etc/host.conf", G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", "/etc/host.conf", "/etc/host.conf",
NULL);
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
"/etc/hosts", G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", "/etc/hosts", "/etc/hosts",
NULL);
/* TODO: Synthesize a passwd with only the user and nobody,
* like Flatpak does? */
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
"/etc/passwd", G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", "/etc/passwd", "/etc/passwd",
NULL);
for (i = 0; from_host[i] != NULL; i++)
{
const char *item = from_host[i];
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
"/etc/group", G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", "/etc/group", "/etc/group",
NULL);
if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1,
item, G_FILE_TEST_EXISTS))
flatpak_bwrap_add_args (bwrap,
"--ro-bind", item, item,
NULL);
}
return TRUE;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment