diff --git a/pressure-vessel/wrap-context.c b/pressure-vessel/wrap-context.c index 9cc0db7b9cb85d850315cd036174ebba2214305e..8216431faebe3a48a4169b8cd0cf1ef470e2a534 100644 --- a/pressure-vessel/wrap-context.c +++ b/pressure-vessel/wrap-context.c @@ -98,6 +98,7 @@ pv_wrap_options_clear (PvWrapOptions *self) enum { PROP_0, + PROP_CURRENT_HOME, PROP_CURRENT_ROOT, N_PROPERTIES }; @@ -133,6 +134,10 @@ pv_wrap_context_get_property (GObject *object, switch (prop_id) { + case PROP_CURRENT_HOME: + g_value_set_string (value, self->current_home); + break; + case PROP_CURRENT_ROOT: g_value_set_object (value, self->current_root); break; @@ -152,6 +157,12 @@ pv_wrap_context_set_property (GObject *object, switch (prop_id) { + case PROP_CURRENT_HOME: + /* Construct-only */ + g_return_if_fail (self->current_home == NULL); + self->current_home = g_value_dup_string (value); + break; + case PROP_CURRENT_ROOT: /* Construct-only */ g_return_if_fail (self->current_root == NULL); @@ -163,6 +174,17 @@ pv_wrap_context_set_property (GObject *object, } } +static void +pv_wrap_context_constructed (GObject *object) +{ + PvWrapContext *self = PV_WRAP_CONTEXT (object); + + G_OBJECT_CLASS (pv_wrap_context_parent_class)->constructed (object); + + if (self->current_home == NULL) + self->current_home = g_strdup (g_get_home_dir ()); +} + static void pv_wrap_context_dispose (GObject *object) { @@ -185,6 +207,7 @@ pv_wrap_context_finalize (GObject *object) g_clear_pointer (&self->paths_not_exported, g_hash_table_unref); g_strfreev (self->original_argv); g_strfreev (self->original_environ); + g_free (self->current_home); G_OBJECT_CLASS (pv_wrap_context_parent_class)->finalize (object); } @@ -196,9 +219,18 @@ pv_wrap_context_class_init (PvWrapContextClass *cls) object_class->get_property = pv_wrap_context_get_property; object_class->set_property = pv_wrap_context_set_property; + object_class->constructed = pv_wrap_context_constructed; object_class->dispose = pv_wrap_context_dispose; object_class->finalize = pv_wrap_context_finalize; + properties[PROP_CURRENT_HOME] = + g_param_spec_string ("current-home", "Current $HOME", + ("Path to real or mock home directory " + "within current-root"), + NULL, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + properties[PROP_CURRENT_ROOT] = g_param_spec_object ("current-root", "Current root", ("Real or mock root directory for the current " @@ -212,10 +244,12 @@ pv_wrap_context_class_init (PvWrapContextClass *cls) PvWrapContext * pv_wrap_context_new (SrtSysroot *current_root, + const char *current_home, GError **error) { /* Can't actually fail right now */ return g_object_new (PV_TYPE_WRAP_CONTEXT, + "current-home", current_home, "current-root", current_root, NULL); } diff --git a/pressure-vessel/wrap-context.h b/pressure-vessel/wrap-context.h index d98ece381bcfbe4d9ab31b128edbe1f02f212416..68cc601a14f0b5cf366419f7b8ef353ba7eef463 100644 --- a/pressure-vessel/wrap-context.h +++ b/pressure-vessel/wrap-context.h @@ -99,6 +99,7 @@ struct _PvWrapContext SrtSysroot *current_root; gchar **original_argv; gchar **original_environ; + gchar *current_home; PvWrapOptions options; @@ -123,6 +124,7 @@ GType pv_wrap_context_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (PvWrapContext, g_object_unref) PvWrapContext *pv_wrap_context_new (SrtSysroot *current_root, + const char *current_home, GError **error); gboolean pv_wrap_options_parse_environment (PvWrapOptions *self, diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c index 35a64dfb5a16d1aa5166df265e957ebf6634e73e..de714d16c4a899563f1390c0d4300aa4bbdcacb7 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -94,7 +94,6 @@ main (int argc, g_autofree gchar *cwd_l = NULL; g_autofree gchar *cwd_p_host = NULL; g_autofree gchar *private_home = NULL; - const gchar *home; g_autofree gchar *tools_dir = NULL; glnx_autofd int original_stdout = -1; glnx_autofd int original_stderr = -1; @@ -139,7 +138,7 @@ main (int argc, if (real_root == NULL) return FALSE; - self = pv_wrap_context_new (real_root, error); + self = pv_wrap_context_new (real_root, g_get_home_dir (), error); if (self == NULL) goto out; @@ -241,8 +240,6 @@ main (int argc, else steam_app_id = _srt_get_steam_app_id (); - home = g_get_home_dir (); - if (self->options.share_home == TRISTATE_YES) { home_mode = PV_HOME_MODE_SHARED; @@ -259,7 +256,7 @@ main (int argc, else if (self->options.freedesktop_app_id) { home_mode = PV_HOME_MODE_PRIVATE; - private_home = g_build_filename (home, ".var", "app", + private_home = g_build_filename (self->current_home, ".var", "app", self->options.freedesktop_app_id, NULL); } @@ -268,7 +265,7 @@ main (int argc, home_mode = PV_HOME_MODE_PRIVATE; self->options.freedesktop_app_id = g_strdup_printf ("com.steampowered.App%s", steam_app_id); - private_home = g_build_filename (home, ".var", "app", + private_home = g_build_filename (self->current_home, ".var", "app", self->options.freedesktop_app_id, NULL); } @@ -768,7 +765,7 @@ main (int argc, bwrap_home_arguments = flatpak_bwrap_new (flatpak_bwrap_empty_env); - if (!pv_wrap_use_home (home_mode, home, private_home, + if (!pv_wrap_use_home (home_mode, self->current_home, private_home, self->exports, bwrap_home_arguments, container_env, error)) goto out; @@ -918,7 +915,7 @@ main (int argc, cwd_p_host = pv_current_namespace_path_to_host_path (cwd_p); - if (_srt_is_same_file (home, cwd_p)) + if (_srt_is_same_file (self->current_home, cwd_p)) { g_info ("Not making physical working directory \"%s\" available to " "container because it is the home directory", @@ -1008,7 +1005,8 @@ main (int argc, flatpak_exports_append_bwrap_args (self->exports, exports_bwrap); g_warn_if_fail (g_strv_length (exports_bwrap->envp) == 0); - if (!pv_bwrap_append_adjusted_exports (bwrap, exports_bwrap, home, + if (!pv_bwrap_append_adjusted_exports (bwrap, exports_bwrap, + self->current_home, interpreter_root, workarounds, error)) goto out; @@ -1031,7 +1029,8 @@ main (int argc, self->is_flatpak_env); g_warn_if_fail (g_strv_length (sharing_bwrap->envp) == 0); - if (!pv_bwrap_append_adjusted_exports (bwrap, sharing_bwrap, home, + if (!pv_bwrap_append_adjusted_exports (bwrap, sharing_bwrap, + self->current_home, interpreter_root, workarounds, error)) goto out; diff --git a/tests/pressure-vessel/wrap-setup.c b/tests/pressure-vessel/wrap-setup.c index bd6e7b7a530d41ab048e70954f0d7c219bc32670..0dfada91955d445b01be26a559cd48076dcad146 100644 --- a/tests/pressure-vessel/wrap-setup.c +++ b/tests/pressure-vessel/wrap-setup.c @@ -242,7 +242,7 @@ setup (Fixture *f, glnx_opendirat (AT_FDCWD, f->var, TRUE, &f->var_fd, &local_error); g_assert_no_error (local_error); - f->context = pv_wrap_context_new (f->mock_host, &local_error); + f->context = pv_wrap_context_new (f->mock_host, "/home/me", &local_error); g_assert_no_error (local_error); f->bwrap = flatpak_bwrap_new (flatpak_bwrap_empty_env);