From f4dff011f78ecd5a69871d4a8ddf3c742de5f621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac=20Jacqu=C3=A9?= Date: Tue, 15 Nov 2022 16:27:16 +0100 Subject: [PATCH] glx: introduce NIX_GLVND_GLX_PATH env variable If NIX_GLVND_GLX_PATH is set, libglvnd will try to load the glx DSOs from the directory it points at instead of loading them from LD_LIBRARY_PATH. --- src/GLX/libglxmapping.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/GLX/libglxmapping.c b/src/GLX/libglxmapping.c index ff2c3a6..a4e54b3 100644 --- a/src/GLX/libglxmapping.c +++ b/src/GLX/libglxmapping.c @@ -407,7 +407,7 @@ __GLXvendorInfo *__glXLookupVendorByName(const char *vendorName) if (!pEntry) { __GLXvendorInfo *vendor; __PFNGLXMAINPROC glxMainProc; - char *filename; + char *filename, *nix_path; int i, count; Bool success; @@ -425,7 +425,24 @@ __GLXvendorInfo *__glXLookupVendorByName(const char *vendorName) filename = ConstructVendorLibraryFilename(vendorName); if (filename) { - vendor->dlhandle = dlopen(filename, RTLD_LAZY); + nix_path = secure_getenv("NIX_GLVND_GLX_PATH"); + if(nix_path) { + size_t nix_path_len; + char* path_sep, *full_path; + nix_path_len = strlen(nix_path); + // Let's make sure we don't end up with a double + // slash in the path. + if (nix_path > 0 && nix_path[nix_path_len - 1] != '/') { + path_sep = "/"; + } else { + path_sep = ""; + } + glvnd_asprintf(&full_path, "%s%s%s", nix_path, path_sep, filename); + vendor->dlhandle = dlopen(full_path, RTLD_LAZY); + free(full_path); + } else { + vendor->dlhandle = dlopen(filename, RTLD_LAZY); + } } free(filename); if (vendor->dlhandle == NULL) {