diff options
author | Eric Anholt <[email protected]> | 2018-11-15 13:54:49 -0800 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2018-11-16 17:49:17 -0800 |
commit | d971a4230d54069c996bca78b6ed6a6a23377821 (patch) | |
tree | 2d9c29c0c0df5405a0bad5b2c7860bcc614069a2 /src/glx/dri_common.c | |
parent | cc198157382a988590b0288d287281139c5f73e6 (diff) |
loader: Factor out the common driver opening logic from each loader.
I copied the code from egl_dri2.c, but the functionality was equivalent
between all the loaders other than their particular environment variables.
v2: Drop the logging function equivalent to loader_default_logger()
(requested by Eric, Emil). Move the SCons workaround across. Drop
the now-unused driGetDriverExtensions() declaration that was lost in a
rebase.
Reviewed-by: Eric Engestrom <[email protected]> (v1)
Reviewed-by: Emil Velikov <[email protected]> (v1)
Diffstat (limited to 'src/glx/dri_common.c')
-rw-r--r-- | src/glx/dri_common.c | 94 |
1 files changed, 8 insertions, 86 deletions
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index b4712a6038b..fb8a29f0993 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -77,9 +77,6 @@ dri_message(int level, const char *f, ...) #define GL_LIB_NAME "libGL.so.1" #endif -static const __DRIextension ** -driGetDriverExtensions(void *handle, const char *driver_name); - /** * Try to \c dlopen the named driver. * @@ -97,98 +94,23 @@ driGetDriverExtensions(void *handle, const char *driver_name); _X_HIDDEN const __DRIextension ** driOpenDriver(const char *driverName, void **out_driver_handle) { - void *glhandle, *handle; - const char *libPaths, *p, *next; - char realDriverName[200]; - int len; + void *glhandle; /* Attempt to make sure libGL symbols will be visible to the driver */ glhandle = dlopen(GL_LIB_NAME, RTLD_NOW | RTLD_GLOBAL); - libPaths = NULL; - if (geteuid() == getuid()) { - /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ - libPaths = getenv("LIBGL_DRIVERS_PATH"); - if (!libPaths) - libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */ - } - if (libPaths == NULL) - libPaths = DEFAULT_DRIVER_DIR; - - handle = NULL; - for (p = libPaths; *p; p = next) { - next = strchr(p, ':'); - if (next == NULL) { - len = strlen(p); - next = p + len; - } - else { - len = next - p; - next++; - } - -#ifdef GLX_USE_TLS - snprintf(realDriverName, sizeof realDriverName, - "%.*s/tls/%s_dri.so", len, p, driverName); - InfoMessageF("OpenDriver: trying %s\n", realDriverName); - handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); -#endif - - if (handle == NULL) { - snprintf(realDriverName, sizeof realDriverName, - "%.*s/%s_dri.so", len, p, driverName); - InfoMessageF("OpenDriver: trying %s\n", realDriverName); - handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); - } - - if (handle != NULL) - break; - else - InfoMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror()); - } + static const char *search_path_vars[] = { + "LIBGL_DRIVERS_PATH", + "LIBGL_DRIVERS_DIR", /* deprecated */ + NULL + }; - if (!handle) - ErrorMessageF("unable to load driver: %s_dri.so\n", driverName); + const __DRIextension **extensions = + loader_open_driver(driverName, out_driver_handle, search_path_vars); if (glhandle) dlclose(glhandle); - const __DRIextension **extensions = driGetDriverExtensions(handle, - driverName); - if (!extensions) { - dlclose(handle); - handle = NULL; - } - - *out_driver_handle = handle; - return extensions; -} - -static const __DRIextension ** -driGetDriverExtensions(void *handle, const char *driver_name) -{ - const __DRIextension **extensions = NULL; - const __DRIextension **(*get_extensions)(void); - char *get_extensions_name = loader_get_extensions_name(driver_name); - - if (get_extensions_name) { - get_extensions = dlsym(handle, get_extensions_name); - if (get_extensions) { - free(get_extensions_name); - return get_extensions(); - } else { - InfoMessageF("driver does not expose %s(): %s\n", - get_extensions_name, dlerror()); - free(get_extensions_name); - } - } - - extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS); - if (extensions == NULL) { - ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - return NULL; - } - return extensions; } |