egl/dri2: use drm macros to construct device name
authorJonathan Gray <jsg@jsg.id.au>
Thu, 3 Apr 2014 05:22:26 +0000 (16:22 +1100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Sat, 5 Apr 2014 12:36:29 +0000 (13:36 +0100)
Don't hardcode /dev/dri/card0 but instead use the drm
macros which allows the correct /dev/drm0 device to be
opened on OpenBSD.

v2: use snprintf and fallback to /dev/dri/card0
v3: check for snprintf truncation

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/egl/drivers/dri2/platform_drm.c

index 2f7edb9f277d96ff090dce369f0c9d0ab6d8e29c..9a7633a070a2f2b0a78197dbbfbf805842cf8c15 100644 (file)
@@ -492,7 +492,12 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
 
    gbm = disp->PlatformDisplay;
    if (gbm == NULL) {
-      fd = open("/dev/dri/card0", O_RDWR);
+      char buf[64];
+      int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);
+      if (n != -1 && n < sizeof(buf))
+         fd = open(buf, O_RDWR);
+      if (fd < 0)
+         fd = open("/dev/dri/card0", O_RDWR);
       dri2_dpy->own_device = 1;
       gbm = gbm_create_device(fd);
       if (gbm == NULL)