From 6977de3339077ea511bf33719500c38ea68affc6 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Fri, 6 Aug 2021 12:27:09 +0100 Subject: [PATCH] pv-runtime: Refactor how we deal with regenerating ld.so.cache The PvRuntime already provides pv-wrap with a pre-configured pv-adverb command-line, so we can repurpose that to include the necessary command-line options to regenerate the ld.so.cache the way we want it. Resolves: https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/issues/74 Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/runtime.c | 79 ++++++++++++++++++++++++++++----------- pressure-vessel/runtime.h | 1 - pressure-vessel/wrap.c | 40 +------------------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index 62fb34ef2..6f19da18a 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 dfb9f19f4..c201a9206 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 13acbb2a3..ef720399f 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -1310,13 +1310,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; @@ -1930,7 +1928,6 @@ main (int argc, exports, bwrap_filesystem_arguments, container_env, - ®enerate_ld_so_cache, error)) goto out; @@ -2368,10 +2365,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; @@ -2514,39 +2507,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 { -- GitLab