[PATCH xserver 4/4] glx: honor LIBGL_DRIVERS_PATH when loading DRI drivers

Nicolai Hähnle nhaehnle at gmail.com
Fri Jan 27 13:37:38 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

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 <nicolai.haehnle at amd.com>
---
 glx/glxdricommon.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/glx/glxdricommon.c b/glx/glxdricommon.c
index f6c6fcd..a370845 100644
--- a/glx/glxdricommon.c
+++ b/glx/glxdricommon.c
@@ -241,28 +241,58 @@ static const char dri_driver_path[] = DRI_DRIVER_PATH;
 void *
 glxProbeDriver(const char *driverName,
                void **coreExt, const char *coreName, int coreVersion,
                void **renderExt, const char *renderName, int renderVersion)
 {
     int i;
     void *driver;
     char filename[PATH_MAX];
     char *get_extensions_name;
     const __DRIextension **extensions = NULL;
+    const char *path = NULL;
+
+    /* 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",
-             dri_driver_path, driverName);
+        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;
     }
 
     if (asprintf(&get_extensions_name, "%s_%s",
                  __DRI_DRIVER_GET_EXTENSIONS, driverName) != -1) {
         const __DRIextension **(*get_extensions)(void);
 
         get_extensions = dlsym(driver, get_extensions_name);
         if (get_extensions)
             extensions = get_extensions();
-- 
2.7.4



More information about the xorg-devel mailing list