summaryrefslogtreecommitdiffstats
path: root/src/glx
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2014-01-23 10:17:11 -0800
committerEric Anholt <eric@anholt.net>2014-01-27 09:36:24 -0800
commitbe7a6976a8335a2e1a177769e96f7310ca6770d1 (patch)
tree8c42f804dc8fbc12c493edb9b9dbaa1a0d4f3b5c /src/glx
parent378e7ad26f11aacd02a131262646e48c362539ef (diff)
dri2: Open the fd before loading the driver.
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. Reviewed-by: Keith Packard <keithp@keithp.com> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
Diffstat (limited to 'src/glx')
-rw-r--r--src/glx/dri2_glx.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index ae807eede04..4e2c16adf22 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;