From 319af6f471912160ab3eb6395ef50f9950063d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Tue, 13 Mar 2018 17:46:37 -0400 Subject: [PATCH] glx: honor LIBGL_DRIVERS_PATH when loading DRI drivers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow switching to another driver build without a full installation. Glamor already takes LIBGL_DRIVERS_PATH into account, so this change makes sure that the same driver is used in both parts of the server. Signed-off-by: Nicolai Hähnle Reviewed-by: Ben Crocker Reviewed-by: Antoine Martin Tested-by: Ben Crocker --- glx/glxdricommon.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/glx/glxdricommon.c b/glx/glxdricommon.c index a16e72849..a6602f930 100644 --- a/glx/glxdricommon.c +++ b/glx/glxdricommon.c @@ -272,14 +272,44 @@ glxProbeDriver(const char *driverName, char filename[PATH_MAX]; char *get_extensions_name; const __DRIextension **extensions = NULL; + const char *path = NULL; - snprintf(filename, sizeof filename, "%s/%s_dri.so", - dri_driver_path, driverName); + /* Search in LIBGL_DRIVERS_PATH if we're not setuid. */ + if (!PrivsElevated()) + path = getenv("LIBGL_DRIVERS_PATH"); + + if (!path) + path = dri_driver_path; + + do { + const char *next; + int path_len; + + next = strchr(path, ':'); + if (next) { + path_len = next - path; + next++; + } else { + path_len = strlen(path); + next = NULL; + } + + snprintf(filename, sizeof filename, "%.*s/%s_dri.so", path_len, path, + driverName); + + driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); + if (driver != NULL) + break; - driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); - if (driver == NULL) { LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n", filename, dlerror()); + + path = next; + } while (path); + + if (driver == NULL) { + LogMessage(X_ERROR, "AIGLX error: unable to load driver %s\n", + driverName); goto cleanup_failure; }