char * loader_get_device_name_for_fd(int fd) { char *device_name = NULL; #ifdef HAVE_LIBUDEV struct udev *udev; struct udev_device *device; const char *const_device_name; UDEV_SYMBOL(struct udev *, udev_new, (void)); UDEV_SYMBOL(const char *, udev_device_get_devnode, (struct udev_device *)); UDEV_SYMBOL(struct udev_device *, udev_device_unref, (struct udev_device *)); UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *)); udev = udev_new(); device = udev_device_new_from_fd(udev, fd); if (device == NULL) return NULL; const_device_name = udev_device_get_devnode(device); if (!const_device_name) goto out; device_name = strdup(const_device_name); out: udev_device_unref(device); udev_unref(udev); #endif return device_name; }
static int libudev_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id) { struct udev *udev = NULL; struct udev_device *device = NULL, *parent; const char *pci_id; UDEV_SYMBOL(struct udev *, udev_new, (void)); UDEV_SYMBOL(struct udev_device *, udev_device_get_parent, (struct udev_device *)); UDEV_SYMBOL(const char *, udev_device_get_property_value, (struct udev_device *, const char *)); UDEV_SYMBOL(struct udev_device *, udev_device_unref, (struct udev_device *)); UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *)); *chip_id = -1; if (dlsym_failed) return 0; udev = udev_new(); device = udev_device_new_from_fd(udev, fd); if (!device) goto out; parent = udev_device_get_parent(device); if (parent == NULL) { log_(_LOADER_WARNING, "MESA-LOADER: could not get parent device\n"); goto out; } pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (pci_id == NULL) { log_(_LOADER_INFO, "MESA-LOADER: no PCI ID\n"); *chip_id = -1; goto out; } else if (sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) { log_(_LOADER_WARNING, "MESA-LOADER: malformed PCI ID\n"); *chip_id = -1; goto out; } out: if (device) udev_device_unref(device); if (udev) udev_unref(udev); return (*chip_id >= 0); }