Try to open the /dev/dri/cardX device once, then only if it fails check the
authorEric Anholt <anholt@freebsd.org>
Thu, 8 Aug 2002 21:23:46 +0000 (21:23 +0000)
committerEric Anholt <anholt@freebsd.org>
Thu, 8 Aug 2002 21:23:46 +0000 (21:23 +0000)
    device number and recreate it if necessary. Fixes xf86drm.c to allow
    linux binaries to be used for emulation on FreeBSD.

libdrm/xf86drm.c

index b5375ee..d2ce5e1 100644 (file)
@@ -229,7 +229,7 @@ static int drmOpenDevice(long dev, int minor)
 
     sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
     drmMsg("drmOpenDevice: node name is %s\n", buf);
-    if (stat(buf, &st) || st.st_rdev != dev) {
+    if (stat(buf, &st)) {
        if (!isroot) return DRM_ERR_NOT_ROOT;
        remove(buf);
        mknod(buf, S_IFCHR | devmode, dev);
@@ -243,6 +243,16 @@ static int drmOpenDevice(long dev, int minor)
     drmMsg("drmOpenDevice: open result is %d, (%s)\n",
                fd, fd < 0 ? strerror(errno) : "OK");
     if (fd >= 0) return fd;
+
+    if (st.st_rdev != dev) {
+       if (!isroot) return DRM_ERR_NOT_ROOT;
+       remove(buf);
+       mknod(buf, S_IFCHR | devmode, dev);
+    }
+    fd = open(buf, O_RDWR, 0);
+    drmMsg("drmOpenDevice: open result is %d, (%s)\n",
+               fd, fd < 0 ? strerror(errno) : "OK");
+
     drmMsg("drmOpenDevice: Open failed\n");
     remove(buf);
     return -errno;