[Mesa-dev] [PATCH 3/7] dri2: Open the fd before loading the driver.

Eric Anholt eric at anholt.net
Thu Jan 23 15:12:11 PST 2014


I want to stop trusting the server for the driver name, and instead decide
on our own based on the fd, so I needed this code motion.
---
 src/glx/dri2_glx.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index ae807ee..4e2c16a 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -1179,6 +1179,20 @@ dri2CreateScreen(int screen, struct glx_display * priv)
       return NULL;
    }
 
+#ifdef O_CLOEXEC
+   psc->fd = open(deviceName, O_RDWR | O_CLOEXEC);
+   if (psc->fd == -1 && errno == EINVAL)
+#endif
+   {
+      psc->fd = open(deviceName, O_RDWR);
+      if (psc->fd != -1)
+         fcntl(psc->fd, F_SETFD, fcntl(psc->fd, F_GETFD) | FD_CLOEXEC);
+   }
+   if (psc->fd < 0) {
+      ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
+      goto handle_error;
+   }
+
    psc->driver = driOpenDriver(driverName);
    if (psc->driver == NULL) {
       ErrorMessageF("driver pointer missing\n");
@@ -1201,20 +1215,6 @@ dri2CreateScreen(int screen, struct glx_display * priv)
       goto handle_error;
    }
 
-#ifdef O_CLOEXEC
-   psc->fd = open(deviceName, O_RDWR | O_CLOEXEC);
-   if (psc->fd == -1 && errno == EINVAL)
-#endif
-   {
-      psc->fd = open(deviceName, O_RDWR);
-      if (psc->fd != -1)
-         fcntl(psc->fd, F_SETFD, fcntl(psc->fd, F_GETFD) | FD_CLOEXEC);
-   }
-   if (psc->fd < 0) {
-      ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
-      goto handle_error;
-   }
-
    if (drmGetMagic(psc->fd, &magic)) {
       ErrorMessageF("failed to get magic\n");
       goto handle_error;
-- 
1.8.5.3



More information about the mesa-dev mailing list