From 01237d30c602ebc14a8c2163dba384b08dfdda0b Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Mon, 13 Nov 2017 00:03:58 +0000 Subject: [PATCH] shim: Take a far more robust approach to `LD_LIBRARY_PATH` This ensures we correctly set up `LD_LIBRARY_PATH` with required extra directories inside the snap environment - only if they actually exist. This allows us to expand that search path to ensure that tls and vdpau bits are available on multiarch systems, and things continue to tick over as normal on biarch systems. This is part of tackling issue #35. Signed-off-by: Ikey Doherty --- src/shim/shim.c | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/shim/shim.c b/src/shim/shim.c index 8f86da2..1c44490 100644 --- a/src/shim/shim.c +++ b/src/shim/shim.c @@ -44,18 +44,6 @@ */ #define REDIRECT_PATH "/usr/\$LIB/liblsi-redirect.so" -/** - * This is the default LD_LIBRARY_PATH we'll want set up under snapd - * to keep things ticking over nicely. - * - * The intercept module will actually take care of a lot of stuff but we'll - * do this for safety. - */ -#define SNAPD_LIBRARY_PATH \ - "/var/lib/snapd/lib/gl/32:/var/lib/snapd/lib/gl:/usr/lib/glx-provider/default:/usr/lib32/" \ - "glx-provider/default" -#define SNAPD_DRIVERS_PATH "/usr/lib/dri:/usr/lib32/dri" - /** * Bi-arch location for the host Vulkan ICD files */ @@ -184,20 +172,62 @@ static bool shim_init_vulkan(const char *glob_path) } #endif +#ifdef HAVE_SNAPD_SUPPORT + +/** + * Attempt to push a path into the variable name if it actually exists + */ +static void shim_export_ld_dir(const char *dir, const char *var_name) +{ + if (!lsi_file_exists(dir)) { + return; + } + shim_export_merge_vars(var_name, NULL, dir); +} + /** * Set up any extra environment pieces that might need fixing * * Currently this only sets up the snapd environmental variables, so that * we don't rely on separate bootstrap scripts out of tree. */ -#ifdef HAVE_SNAPD_SUPPORT static void shim_export_extra(const char *prefix) { static const char *snap_user = NULL; static const char *xdg_home = NULL; - setenv("LIBGL_DRIVERS_PATH", SNAPD_LIBRARY_PATH, 1); - setenv("LD_LIBRARY_PATH", SNAPD_LIBRARY_PATH ":" SNAPD_DRIVERS_PATH, 1); + /* Add all of these guys to LD_LIBRARY_PATH if they exist. + * This allows us to handle the special-case multiarch mounts. + */ + static const char *ld_library_dirs[] = { + "/var/lib/snapd/lib/gl/vdpau", /**