diff -ur libdrm-2.4.5.old/libdrm/xf86drm.c libdrm-2.4.5/libdrm/xf86drm.c --- libdrm-2.4.5.old/libdrm/xf86drm.c 2009-05-01 11:36:29.000000000 -0500 +++ libdrm-2.4.5/libdrm/xf86drm.c 2009-05-01 11:31:16.000000000 -0500 @@ -2417,9 +2417,19 @@ { int i; int fd; + struct stat drmStat; for (i = 0; i < nr_fds; i++) if (strcmp(BusID, connection[i].BusID) == 0) { + /* Check if the fd is still valid... server restart may have closed the fd on us! */ + if (fstat(connection[i].fd, &drmStat) == -1) + { + fprintf(stderr, "libdrm - tried to re-use a closed file descriptor %d for %s, refcount = %d\n", + connection[i].fd, BusID, connection[i].refcount); + connection[i].fd = drmOpen(unused, BusID); + *newlyopened = 0; + return connection[i].fd; + } connection[i].refcount++; *newlyopened = 0; return connection[i].fd;