From 8f18e3c0510f48ffc168de2c434e2557c3c543db Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 1 Aug 2019 13:53:18 +0100
Subject: [PATCH] wrap: Make it clearer what we are doing when manipulating
 ld.so

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/wrap.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/wrap.c b/src/wrap.c
index 7ab733d89..6c1e9dbb3 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -1140,7 +1140,10 @@ bind_runtime (FlatpakBwrap *bwrap,
               g_autofree gchar *real_path_in_host = NULL;
               g_autofree gchar *real_path_in_runtime = NULL;
 
+              g_debug ("Making host ld.so visible in container");
+
               real_path_in_host = flatpak_canonicalize_filename (ld_so);
+              g_debug ("Host path: %s -> %s", ld_so, real_path_in_host);
 
               g_clear_pointer (&temp_bwrap, flatpak_bwrap_free);
 
@@ -1158,9 +1161,21 @@ bind_runtime (FlatpakBwrap *bwrap,
               if (real_path_in_runtime == NULL)
                 return FALSE;
 
-              if (runtime_is_usr
-                  || g_str_has_prefix (real_path_in_runtime, "/usr/"))
+              g_debug ("Container path: %s -> %s", ld_so, real_path_in_runtime);
+
+              if (runtime_is_usr)
                 {
+                  g_debug ("Runtime is just /usr anyway");
+                  g_debug ("Mounting %s on %s", real_path_in_host, real_path_in_runtime);
+                  flatpak_bwrap_add_args (bwrap,
+                                          "--ro-bind", real_path_in_host,
+                                          real_path_in_runtime,
+                                          NULL);
+                }
+              else if (g_str_has_prefix (real_path_in_runtime, "/usr/"))
+                {
+                  g_debug ("Path in runtime starts with /usr already");
+                  g_debug ("Mounting %s on %s", real_path_in_host, real_path_in_runtime);
                   flatpak_bwrap_add_args (bwrap,
                                           "--ro-bind", real_path_in_host,
                                           real_path_in_runtime,
@@ -1168,9 +1183,13 @@ bind_runtime (FlatpakBwrap *bwrap,
                 }
               else
                 {
-                  /* /lib, /lib64 are just going to be symlinks anyway */
+                  /* We assume that /lib, /lib64 are just going to be
+                   * symlinks anyway.
+                   *
+                   * TODO: Support for non-merged-/usr runtimes? */
                   g_autofree gchar *usr_path_in_runtime = NULL;
 
+                  g_debug ("Assuming runtime is merged-/usr");
                   usr_path_in_runtime = g_build_filename ("/usr",
                                                           real_path_in_runtime,
                                                           NULL);
@@ -1180,6 +1199,8 @@ bind_runtime (FlatpakBwrap *bwrap,
                                           NULL);
                 }
 
+              g_debug ("Making host locale data visible in container");
+
               if (g_file_test ("/usr/lib/locale", G_FILE_TEST_EXISTS))
                 flatpak_bwrap_add_args (bwrap,
                                         "--ro-bind", "/usr/lib/locale",
-- 
GitLab