From 69323bb0bef4d747876f3aa032e8b144d37d4b52 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 4 Oct 2017 13:34:55 +0200 Subject: [PATCH] LD_LIBRARY_PATH: Fix order of extension libs We prepend the app extensions, so they are before /app/lib, but we append the runtime extensions so they are after /app/lib. This matches what is described in https://github.com/flatpak/flatpak/issues/1075 Closes: #1076 Approved by: alexlarsson (cherry picked from commit f7a1c9fe7c3a854481286927c6292f2b9b20894e) Closes: #1115 Approved by: alexlarsson --- common/flatpak-run.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/common/flatpak-run.c b/common/flatpak-run.c index 53b61170..ff7299fb 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -2198,6 +2198,7 @@ flatpak_run_add_extension_args (GPtrArray *argv_array, g_auto(GStrv) parts = NULL; gboolean is_app; GList *extensions, *l; + g_autoptr(GString) ld_library_path = g_string_new (""); g_autoptr(GHashTable) mounted_tmpfs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); g_autoptr(GHashTable) created_symlink = @@ -2246,15 +2247,9 @@ flatpak_run_add_extension_args (GPtrArray *argv_array, if (ext->add_ld_path) { g_autofree char *ld_path = g_build_filename (full_directory, ext->add_ld_path, NULL); - const gchar *old_ld_path = g_environ_getenv (*envp_p, "LD_LIBRARY_PATH"); - g_autofree char *new_ld_path = NULL; - - if (old_ld_path != NULL) - new_ld_path = g_strconcat (old_ld_path, ":", ld_path, NULL); - else - new_ld_path = g_strdup (new_ld_path); - - *envp_p = g_environ_setenv (*envp_p, "LD_LIBRARY_PATH", new_ld_path , TRUE); + if (ld_library_path->len != 0) + g_string_append (ld_library_path, ":"); + g_string_append (ld_library_path, ld_path); } for (i = 0; ext->merge_dirs != NULL && ext->merge_dirs[i] != NULL; i++) @@ -2286,6 +2281,27 @@ flatpak_run_add_extension_args (GPtrArray *argv_array, g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free); + if (ld_library_path->len != 0) + { + const gchar *old_ld_path = g_environ_getenv (*envp_p, "LD_LIBRARY_PATH"); + + if (old_ld_path != NULL && *old_ld_path != 0) + { + if (is_app) + { + g_string_append (ld_library_path, ":"); + g_string_append (ld_library_path, old_ld_path); + } + else + { + g_string_prepend (ld_library_path, ":"); + g_string_prepend (ld_library_path, old_ld_path); + } + } + + *envp_p = g_environ_setenv (*envp_p, "LD_LIBRARY_PATH", ld_library_path->str , TRUE); + } + return TRUE; }