- const __DRIextension **extensions = NULL;
- char path[PATH_MAX], *search_paths, *next, *end;
- char *get_extensions_name;
- const __DRIextension **(*get_extensions)(void);
-
- search_paths = NULL;
- if (geteuid() == getuid()) {
- /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
- search_paths = getenv("LIBGL_DRIVERS_PATH");
- }
- if (search_paths == NULL)
- search_paths = DEFAULT_DRIVER_DIR;
-
- dri2_dpy->driver = NULL;
- end = search_paths + strlen(search_paths);
- for (char *p = search_paths; p < end; p = next + 1) {
- int len;
- next = strchr(p, ':');
- if (next == NULL)
- next = end;
-
- len = next - p;
-#if GLX_USE_TLS
- snprintf(path, sizeof path,
- "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name);
- dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
-#endif
- if (dri2_dpy->driver == NULL) {
- snprintf(path, sizeof path,
- "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name);
- dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
- if (dri2_dpy->driver == NULL)
- _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror());
- }
- /* not need continue to loop all paths once the driver is found */
- if (dri2_dpy->driver != NULL)
- break;
- }
-
- if (dri2_dpy->driver == NULL) {
- _eglLog(_EGL_WARNING,
- "DRI2: failed to open %s (search paths %s)",
- dri2_dpy->driver_name, search_paths);
- return NULL;
- }
-
- _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
-
- get_extensions_name = loader_get_extensions_name(dri2_dpy->driver_name);
- if (get_extensions_name) {
- get_extensions = dlsym(dri2_dpy->driver, get_extensions_name);
- if (get_extensions) {
- extensions = get_extensions();
- } else {
- _eglLog(_EGL_DEBUG, "driver does not expose %s(): %s\n",
- get_extensions_name, dlerror());
- }
- free(get_extensions_name);
- }
-
- if (!extensions)
- extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS);
- if (extensions == NULL) {
- _eglLog(_EGL_WARNING,
- "DRI2: driver exports no extensions (%s)", dlerror());
- dlclose(dri2_dpy->driver);
- }