+ psc->fd = loader_open_device(deviceName);
+ 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;
+ }
+
+ if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) {
+ ErrorMessageF("failed to authenticate magic %d\n", magic);
+ goto handle_error;
+ }
+
+ /* If Mesa knows about the appropriate driver for this fd, then trust it.
+ * Otherwise, default to the server's value.
+ */
+ loader_driverName = loader_get_driver_for_fd(psc->fd);
+ if (loader_driverName) {
+ free(driverName);
+ driverName = loader_driverName;
+ }
+