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 | |
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')
-rw-r--r-- | src/glx/Makefile.am | 1 | ||||
-rw-r--r-- | src/glx/SConscript | 2 | ||||
-rw-r--r-- | src/glx/dri_common.c | 94 | ||||
-rw-r--r-- | src/glx/meson.build | 1 |
4 files changed, 8 insertions, 90 deletions
diff --git a/src/glx/Makefile.am b/src/glx/Makefile.am index 8f9d80c9f41..d208ce14bb7 100644 --- a/src/glx/Makefile.am +++ b/src/glx/Makefile.am @@ -40,7 +40,6 @@ AM_CFLAGS = \ $(VISIBILITY_CFLAGS) \ $(EXTRA_DEFINES_XF86VIDMODE) \ -D_REENTRANT \ - -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" \ $(DEFINES) \ $(LIBDRM_CFLAGS) \ $(DRI2PROTO_CFLAGS) \ diff --git a/src/glx/SConscript b/src/glx/SConscript index 83c62e22f8c..7555fb0568c 100644 --- a/src/glx/SConscript +++ b/src/glx/SConscript @@ -26,8 +26,6 @@ env.Append(CPPDEFINES = [ '_REENTRANT', ]) -env.Append(CPPDEFINES = ['DEFAULT_DRIVER_DIR=\\"/usr/local/lib/dri\\"']) - env.Prepend(LIBS = [ libloader, mesautil, 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; } diff --git a/src/glx/meson.build b/src/glx/meson.build index dd8ba60ad80..1de35fca6bc 100644 --- a/src/glx/meson.build +++ b/src/glx/meson.build @@ -134,7 +134,6 @@ endif gl_lib_cargs = [ '-D_REENTRANT', - '-DDEFAULT_DRIVER_DIR="@0@"'.format(dri_search_path), ] if dep_xxf86vm.found() |