diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index 443bd05f5280bb4d2f186257f13603d488f06027..59910dfa9bfa6d8dba40fc93173e146412a4bf9b 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -1837,6 +1837,62 @@ pv_runtime_new (const char *source, NULL); } +static void +pv_runtime_adverb_regenerate_ld_so_cache (PvRuntime *self, + FlatpakBwrap *adverb_argv) +{ + g_autoptr(GString) ldlp_after_regen = g_string_new (""); + g_autofree gchar *regen_dir = NULL; + gsize i; + + /* This directory was set up in bind_runtime_ld_so() */ + if (self->is_flatpak_env) + { + const gchar *xrd; + + /* As in bind_runtime_ld_so(), we expect Flatpak to provide this + * in practice, even if the host system does not. */ + xrd = g_environ_getenv (self->original_environ, "XDG_RUNTIME_DIR"); + g_return_if_fail (xrd != NULL); + + regen_dir = g_build_filename (xrd, "pressure-vessel", "ldso", NULL); + } + else + { + regen_dir = g_strdup ("/run/pressure-vessel/ldso"); + } + + flatpak_bwrap_add_args (adverb_argv, + "--regenerate-ld.so-cache", regen_dir, + NULL); + + /* This logic to build the search path matches + * pv_runtime_set_search_paths(), except that here, we split them up: + * the directories containing SONAMEs go in ld.so.conf, and only the + * directories containing aliases go in LD_LIBRARY_PATH. */ + for (i = 0; i < PV_N_SUPPORTED_ARCHITECTURES; i++) + { + g_autofree gchar *ld_path = NULL; + g_autofree gchar *aliases = NULL; + + ld_path = g_build_filename (self->overrides_in_container, "lib", + pv_multiarch_tuples[i], NULL); + + aliases = g_build_filename (self->overrides_in_container, "lib", + pv_multiarch_tuples[i], "aliases", NULL); + + flatpak_bwrap_add_args (adverb_argv, + "--add-ld.so-path", ld_path, + NULL); + + pv_search_path_append (ldlp_after_regen, aliases); + } + + flatpak_bwrap_add_args (adverb_argv, + "--set-ld-library-path", ldlp_after_regen->str, + NULL); +} + /* If we are using a runtime, ensure the locales to be generated, * pass the lock fd to the executed process, * and make it act as a subreaper for the game itself. @@ -1895,6 +1951,8 @@ pv_runtime_get_adverb (PvRuntime *self, NULL); } + pv_runtime_adverb_regenerate_ld_so_cache (self, bwrap); + return TRUE; } @@ -5459,7 +5517,6 @@ pv_runtime_bind (PvRuntime *self, FlatpakExports *exports, FlatpakBwrap *bwrap, PvEnviron *container_env, - gchar **regenerate_ld_so_cache, GError **error) { g_return_val_if_fail (PV_IS_RUNTIME (self), FALSE); @@ -5614,26 +5671,6 @@ pv_runtime_bind (PvRuntime *self, pv_runtime_set_search_paths (self, container_env); - if (regenerate_ld_so_cache != NULL) - { - if (self->is_flatpak_env) - { - const gchar *xrd; - /* As in bind_runtime_ld_so(), we expect Flatpak to provide this - * in practice, even if the host system does not. */ - xrd = g_environ_getenv (self->original_environ, "XDG_RUNTIME_DIR"); - if (xrd == NULL) - *regenerate_ld_so_cache = NULL; - else - *regenerate_ld_so_cache = g_build_filename (xrd, "pressure-vessel", - "ldso", NULL); - } - else - { - *regenerate_ld_so_cache = g_strdup ("/run/pressure-vessel/ldso"); - } - } - return TRUE; } diff --git a/pressure-vessel/runtime.h b/pressure-vessel/runtime.h index 6370deea3b411809feeed5bc61f6b7ca6004d93b..1e0620b9c031874c1d778adfa8e615b68f6dfc64 100644 --- a/pressure-vessel/runtime.h +++ b/pressure-vessel/runtime.h @@ -98,7 +98,6 @@ gboolean pv_runtime_bind (PvRuntime *self, FlatpakExports *exports, FlatpakBwrap *bwrap, PvEnviron *container_env, - gchar **regenerate_ld_so_cache, GError **error); const char *pv_runtime_get_modified_usr (PvRuntime *self); const char *pv_runtime_get_modified_app (PvRuntime *self); diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c index 38fe6b7db2736771928cff87538148a76b30bc6c..7d0fbce2d82cc60df8154ec898a3f8f8f31d2055 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -1340,13 +1340,11 @@ main (int argc, g_autofree gchar *cwd_p = NULL; g_autofree gchar *cwd_l = NULL; g_autofree gchar *cwd_p_host = NULL; - g_autofree gchar *container_ld_library_path = NULL; const gchar *home; g_autofree gchar *tools_dir = NULL; g_autoptr(PvRuntime) runtime = NULL; g_autoptr(FILE) original_stdout = NULL; g_autoptr(GArray) pass_fds_through_adverb = g_array_new (FALSE, FALSE, sizeof (int)); - g_autofree gchar *regenerate_ld_so_cache = NULL; const char *steam_app_id; g_autoptr(GPtrArray) adverb_preload_argv = NULL; int result; @@ -1965,7 +1963,6 @@ main (int argc, exports, bwrap_filesystem_arguments, container_env, - ®enerate_ld_so_cache, error)) goto out; @@ -2309,10 +2306,6 @@ main (int argc, goto out; } - /* Save this value before freeing container_env */ - container_ld_library_path = g_strdup (pv_environ_getenv (container_env, - "LD_LIBRARY_PATH")); - if (is_flatpak_env) { g_autoptr(GList) vars = NULL; @@ -2455,39 +2448,10 @@ main (int argc, if (runtime != NULL) { + /* This includes the arguments necessary to regenerate the + * ld.so cache */ if (!pv_runtime_get_adverb (runtime, adverb_argv)) goto out; - - if (regenerate_ld_so_cache != NULL) - { - g_autoptr(GString) adverb_ld_library_path = g_string_new (""); - g_auto(GStrv) parts = NULL; - - flatpak_bwrap_add_args (adverb_argv, - "--regenerate-ld.so-cache", - regenerate_ld_so_cache, - NULL); - - if (container_ld_library_path != NULL) - parts = g_strsplit (container_ld_library_path, ":", 0); - - for (i = 0; parts != NULL && parts[i] != NULL; i++) - { - if (g_str_has_suffix (parts[i], "/aliases")) - pv_search_path_append (adverb_ld_library_path, parts[i]); - else - flatpak_bwrap_add_args (adverb_argv, - "--add-ld.so-path", - parts[i], - NULL); - } - - if (adverb_ld_library_path->len > 0) - flatpak_bwrap_add_args (adverb_argv, - "--set-ld-library-path", - adverb_ld_library_path->str, - NULL); - } } else {