On Mon, Feb 1, 2010 at 7:34 PM, Chia-I Wu <olva...@gmail.com> wrote:
> On Tue, Feb 2, 2010 at 2:49 AM, Mike Stroyan <m...@lunarg.com> wrote:
>>  Here is a version of the patch that uses EGL_DRIVERS_PATH and checks
>> for setuid/setgid
>> before using EGL_DRIVER or EGL_DRIVERS_PATH.
> The patch seems to be missing :)

Here is the missing patch file.

-- 

 Mike Stroyan - Software Architect
 LunarG, Inc.  - The Graphics Experts
 Cell:  (970) 219-7905
 Email: m...@lunarg.com
 Website: http://www.lunarg.com
From 4afd26abdeca4c0f600078abc21f000983296911 Mon Sep 17 00:00:00 2001
From: Mike Stroyan <m...@lunarg.com>
Date: Mon, 1 Feb 2010 14:32:40 -0700
Subject: [PATCH] Use EGL_DRIVERS_PATH

---
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index df36369..b31b631 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -56,7 +56,7 @@ close_library(HMODULE lib)
 static const char *
 library_suffix(void)
 {
-   return "dll";
+   return ".dll";
 }
 
 
@@ -64,10 +64,18 @@ static EGLBoolean
 make_library_path(char *buf, unsigned int size, const char *name)
 {
    EGLBoolean need_suffix;
-   const char *suffix = ".dll";
+   const char *suffix = library_suffix();
    int ret;
 
-   need_suffix = (strchr(name, '.') == NULL);
+   /* match the suffix */
+   if (suffix) {
+      size_t name_len = strlen(name);
+      size_t suffix_len = strlen(suffix);
+      need_suffix = (name_len < suffix_len
+         || strcmp(name + name_len - suffix_len, suffix) != 0);
+   } else {
+      need_suffix = EGL_FALSE;
+   }
    ret = snprintf(buf, size, "%s%s", name, (need_suffix) ? suffix : "");
 
    return ((unsigned int) ret < size);
@@ -84,7 +92,25 @@ typedef void * lib_handle;
 static void *
 open_library(const char *filename)
 {
-   return dlopen(filename, RTLD_LAZY);
+   void *handle;
+
+   /* first try opening without an explicit directory to allow search path */
+   handle = dlopen(filename, RTLD_LAZY);
+   if (handle) {
+      return handle;
+   }
+
+   /* if plain file unfound try adding _EGL_DRIVER_SEARCH_DIR directory */
+   if (strchr(filename, '/') == NULL) {
+      char path[1024];
+      int ret;
+      ret = snprintf(path, sizeof(path), "%s%s",
+            _EGL_DRIVER_SEARCH_DIR"/", filename);
+      if ((unsigned int) ret < sizeof(path)) {
+         return dlopen(path, RTLD_LAZY);
+      }
+   }
+   return NULL;
 }
 
 static void
@@ -97,23 +123,27 @@ close_library(void *lib)
 static const char *
 library_suffix(void)
 {
-   return "so";
+   return ".so";
 }
 
 
 static EGLBoolean
 make_library_path(char *buf, unsigned int size, const char *name)
 {
-   EGLBoolean need_dir, need_suffix;
-   const char *suffix = ".so";
+   EGLBoolean need_suffix;
+   const char *suffix = library_suffix();
    int ret;
 
-   need_dir = (strchr(name, '/') == NULL);
-   need_suffix = (strchr(name, '.') == NULL);
-
-   ret = snprintf(buf, size, "%s%s%s",
-         (need_dir) ? _EGL_DRIVER_SEARCH_DIR"/" : "", name,
-         (need_suffix) ? suffix : "");
+   /* match the suffix */
+   if (suffix) {
+      size_t name_len = strlen(name);
+      size_t suffix_len = strlen(suffix);
+      need_suffix = (name_len < suffix_len
+         || strcmp(name + name_len - suffix_len, suffix) != 0);
+   } else {
+      need_suffix = EGL_FALSE;
+   }
+   ret = snprintf(buf, size, "%s%s", name, (need_suffix) ? suffix : "");
 
    return ((unsigned int) ret < size);
 }
@@ -333,55 +363,39 @@ _eglPreloadUserDriver(void)
 #endif
 }
 
-
+#if defined(_EGL_PLATFORM_POSIX)
 /**
- * Preload display drivers.
- *
- * Display drivers are a set of drivers that support a certain display system.
- * The display system may be specified by EGL_DISPLAY.
- *
- * FIXME This makes libEGL a memory hog if an user driver is not specified and
- * there are many display drivers.
+ * Preload display drivers found in a particular directory.
  */
-static EGLBoolean
-_eglPreloadDisplayDrivers(void)
+static void
+_eglPreloadDisplayDriversFromDir(const char *prefix, const char *suffix, const char *dir)
 {
-#if defined(_EGL_PLATFORM_POSIX)
-   const char *dpy, *suffix;
-   char path[1024], prefix[32];
+   char path[1024];
    DIR *dirp;
    struct dirent *dirent;
 
-   dpy = getenv("EGL_DISPLAY");
-   if (!dpy || !dpy[0])
-      dpy = _EGL_DEFAULT_DISPLAY;
-   if (!dpy || !dpy[0])
-      return EGL_FALSE;
-
-   snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
-   suffix = library_suffix();
-
-   dirp = opendir(_EGL_DRIVER_SEARCH_DIR);
+   dirp = opendir(dir);
    if (!dirp)
-      return EGL_FALSE;
+      return;
 
    while ((dirent = readdir(dirp))) {
       _EGLDriver *drv;
-      const char *p;
 
       /* match the prefix */
       if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
          continue;
 
       /* match the suffix */
-      p = strrchr(dirent->d_name, '.');
-      if ((p && !suffix) || (!p && suffix))
-         continue;
-      else if (p && suffix && strcmp(p + 1, suffix) != 0)
-         continue;
+      if (suffix) {
+         size_t d_name_len = strlen(dirent->d_name);
+         size_t suffix_len = strlen(suffix);
+         if (d_name_len < suffix_len)
+            continue;
+         if (strcmp(dirent->d_name + d_name_len - suffix_len, suffix) != 0)
+            continue;
+      }
 
-      snprintf(path, sizeof(path),
-            _EGL_DRIVER_SEARCH_DIR"/%s", dirent->d_name);
+      snprintf(path, sizeof(path), "%s/%s", dir, dirent->d_name);
 
       drv = _eglLoadDriver(path, NULL);
       if (drv)
@@ -389,6 +403,55 @@ _eglPreloadDisplayDrivers(void)
    }
 
    closedir(dirp);
+}
+#endif
+
+/**
+ * Preload display drivers.
+ *
+ * Display drivers are a set of drivers that support a certain display system.
+ * The display system may be specified by EGL_DISPLAY.
+ * The directories containing drivers can be set by EGL_DRIVERS_PATH.
+ *
+ * FIXME This makes libEGL a memory hog if an user driver is not specified and
+ * there are many display drivers.
+ */
+static EGLBoolean
+_eglPreloadDisplayDrivers(void)
+{
+#if defined(_EGL_PLATFORM_POSIX)
+   const char *dpy;
+   char *libpath, *saveptr, *dir;
+   char prefix[32];
+   EGLBoolean use_env = (geteuid() == getuid() && getegid() == getgid());
+
+   dpy = NULL;
+   /* Don't use EGL_DISPLAY for setuid or setgid programs. */
+   if (use_env) dpy = getenv("EGL_DISPLAY");
+   if (!dpy || !dpy[0])
+      dpy = _EGL_DEFAULT_DISPLAY;
+   if (!dpy || !dpy[0])
+      return EGL_FALSE;
+
+   snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
+
+   /* Try loading drivers from $EGL_DRIVERS_PATH as well as _EGL_DRIVER_SEARCH_DIR. */
+   /* Don't use EGL_DRIVERS_PATH for setuid or setgid programs. */
+   if (use_env) {
+      libpath = getenv("EGL_DRIVERS_PATH");
+      /* Copy before strtok_r modifies libpath. */
+      if (libpath) libpath = strdup(libpath);
+      if (libpath) {
+         dir = strtok_r(libpath, ":", &saveptr);
+         while (dir) {
+            _eglPreloadDisplayDriversFromDir(prefix, library_suffix(), dir);
+            dir = strtok_r(NULL, ":", &saveptr);
+         }
+         free(libpath);
+      }
+   }
+
+   _eglPreloadDisplayDriversFromDir(prefix, library_suffix(), _EGL_DRIVER_SEARCH_DIR);
 
    return (_eglGlobal.NumDrivers > 0);
 #else /* _EGL_PLATFORM_POSIX */
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to