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

pv-wrap: Have a file descriptor for $HOME in the PvWrapContext


This will allow the LD_PRELOAD handling code to use a real or mock
home directory, as appropriate.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 44855f60
No related branches found
No related tags found
1 merge request!785Export parent directory of LD_PRELOAD modules
...@@ -117,6 +117,7 @@ pv_wrap_context_init (PvWrapContext *self) ...@@ -117,6 +117,7 @@ pv_wrap_context_init (PvWrapContext *self)
{ {
self->is_flatpak_env = g_file_test ("/.flatpak-info", G_FILE_TEST_IS_REGULAR); self->is_flatpak_env = g_file_test ("/.flatpak-info", G_FILE_TEST_IS_REGULAR);
self->original_environ = g_get_environ (); self->original_environ = g_get_environ ();
self->current_home_fd = -1;
pv_wrap_options_init (&self->options); pv_wrap_options_init (&self->options);
...@@ -178,11 +179,27 @@ static void ...@@ -178,11 +179,27 @@ static void
pv_wrap_context_constructed (GObject *object) pv_wrap_context_constructed (GObject *object)
{ {
PvWrapContext *self = PV_WRAP_CONTEXT (object); PvWrapContext *self = PV_WRAP_CONTEXT (object);
g_autoptr(GError) local_error = NULL;
G_OBJECT_CLASS (pv_wrap_context_parent_class)->constructed (object); G_OBJECT_CLASS (pv_wrap_context_parent_class)->constructed (object);
if (self->current_home == NULL) if (self->current_home == NULL)
self->current_home = g_strdup (g_get_home_dir ()); self->current_home = g_strdup (g_get_home_dir ());
self->current_home_fd = _srt_sysroot_open (self->current_root,
self->current_home,
(SRT_RESOLVE_FLAGS_READABLE
| SRT_RESOLVE_FLAGS_MUST_BE_DIRECTORY),
NULL,
&local_error);
if (self->current_home_fd < 0)
{
g_warning ("Cannot open current home directory \"%s\": %s",
self->current_home, local_error->message);
g_clear_error (&local_error);
}
} }
static void static void
...@@ -208,6 +225,7 @@ pv_wrap_context_finalize (GObject *object) ...@@ -208,6 +225,7 @@ pv_wrap_context_finalize (GObject *object)
g_strfreev (self->original_argv); g_strfreev (self->original_argv);
g_strfreev (self->original_environ); g_strfreev (self->original_environ);
g_free (self->current_home); g_free (self->current_home);
glnx_close_fd (&self->current_home_fd);
G_OBJECT_CLASS (pv_wrap_context_parent_class)->finalize (object); G_OBJECT_CLASS (pv_wrap_context_parent_class)->finalize (object);
} }
......
...@@ -105,6 +105,7 @@ struct _PvWrapContext ...@@ -105,6 +105,7 @@ struct _PvWrapContext
gboolean is_flatpak_env; gboolean is_flatpak_env;
int original_argc; int original_argc;
int current_home_fd;
}; };
#define PV_TYPE_WRAP_CONTEXT \ #define PV_TYPE_WRAP_CONTEXT \
......
...@@ -915,7 +915,8 @@ main (int argc, ...@@ -915,7 +915,8 @@ main (int argc,
cwd_p_host = pv_current_namespace_path_to_host_path (cwd_p); cwd_p_host = pv_current_namespace_path_to_host_path (cwd_p);
if (_srt_is_same_file (self->current_home, cwd_p)) if (self->current_home_fd >= 0
&& _srt_fstatat_is_same_file (self->current_home_fd, "", AT_FDCWD, cwd_p))
{ {
g_info ("Not making physical working directory \"%s\" available to " g_info ("Not making physical working directory \"%s\" available to "
"container because it is the home directory", "container because it is the home directory",
......
...@@ -80,6 +80,7 @@ typedef struct ...@@ -80,6 +80,7 @@ typedef struct
PvWrapContext *context; PvWrapContext *context;
SrtSysroot *mock_host; SrtSysroot *mock_host;
FlatpakBwrap *bwrap; FlatpakBwrap *bwrap;
gchar *home;
gchar *tmpdir; gchar *tmpdir;
gchar *mock_runtime; gchar *mock_runtime;
gchar *var; gchar *var;
...@@ -242,6 +243,9 @@ setup (Fixture *f, ...@@ -242,6 +243,9 @@ setup (Fixture *f,
glnx_opendirat (AT_FDCWD, f->var, TRUE, &f->var_fd, &local_error); glnx_opendirat (AT_FDCWD, f->var, TRUE, &f->var_fd, &local_error);
g_assert_no_error (local_error); g_assert_no_error (local_error);
f->home = g_build_filename (f->mock_host->path, "home", "me", NULL);
glnx_shutil_mkdir_p_at (AT_FDCWD, f->home, 0755, NULL, &local_error);
g_assert_no_error (local_error);
f->context = pv_wrap_context_new (f->mock_host, "/home/me", &local_error); f->context = pv_wrap_context_new (f->mock_host, "/home/me", &local_error);
g_assert_no_error (local_error); g_assert_no_error (local_error);
f->bwrap = flatpak_bwrap_new (flatpak_bwrap_empty_env); f->bwrap = flatpak_bwrap_new (flatpak_bwrap_empty_env);
...@@ -311,6 +315,7 @@ teardown (Fixture *f, ...@@ -311,6 +315,7 @@ teardown (Fixture *f,
g_clear_object (&f->context); g_clear_object (&f->context);
g_clear_object (&f->mock_host); g_clear_object (&f->mock_host);
g_clear_pointer (&f->mock_runtime, g_free); g_clear_pointer (&f->mock_runtime, g_free);
g_clear_pointer (&f->home, g_free);
g_clear_pointer (&f->tmpdir, g_free); g_clear_pointer (&f->tmpdir, g_free);
g_clear_pointer (&f->var, g_free); g_clear_pointer (&f->var, g_free);
g_clear_pointer (&f->bwrap, flatpak_bwrap_free); g_clear_pointer (&f->bwrap, flatpak_bwrap_free);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment