chiark / gitweb /
vol_id: fix language in manpage
[elogind.git] / extras / usb_id / usb_id.c
index 489f97e5376da9a9953dc91c73be4d6e9b1165f1..b15263ef7deff5eb0c2f5c02d0b39cee6bfef22a 100644 (file)
@@ -186,7 +186,7 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len
                u_int8_t        bInterfaceProtocol;
                u_int8_t        iInterface;
        } __attribute__((packed));
-       int err;
+       int err = 0;
 
        if (asprintf(&filename, "%s/descriptors", udev_device_get_syspath(dev)) < 0) {
                err = -1;
@@ -233,14 +233,13 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len
        }
 out:
        free(filename);
-       return 0;
+       return err;
 }
 
 /*
  * A unique USB identification is generated like this:
  *
- * 1.) Get the USB device type from DeviceClass, InterfaceClass
- *     and InterfaceSubClass
+ * 1.) Get the USB device type from InterfaceClass and InterfaceSubClass
  * 2.) If the device type is 'Mass-Storage/SPC-2' or 'Mass-Storage/RBC'
  *     use the SCSI vendor and model as USB-Vendor and USB-model.
  * 3.) Otherwise use the USB manufacturer and product as
@@ -257,14 +256,21 @@ out:
 static int usb_id(struct udev_device *dev)
 {
        struct udev *udev = udev_device_get_udev(dev);
-       struct udev_device *dev_interface;
-       struct udev_device *dev_usb;
+       struct udev_device *dev_interface = NULL;
+       struct udev_device *dev_usb = NULL;
        const char *if_class, *if_subclass;
        int if_class_num;
        int protocol = 0;
 
        dbg(udev, "syspath %s\n", udev_device_get_syspath(dev));
 
+       /* shortcut, if we are called directly for a "usb_device" type */
+       if (udev_device_get_devtype(dev) != NULL && strcmp(udev_device_get_devtype(dev), "usb_device") == 0) {
+               dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str));
+               dev_usb = dev;
+               goto fallback;
+       }
+
        /* usb interface directory */
        dev_interface = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface");
        if (dev_interface == NULL) {
@@ -526,7 +532,8 @@ int main(int argc, char **argv)
                        printf("ID_SERIAL=%s\n", serial);
                        if (serial_str[0] != '\0')
                                printf("ID_SERIAL_SHORT=%s\n", serial_str);
-                       printf("ID_TYPE=%s\n", type_str);
+                       if (type_str[0] != '\0')
+                               printf("ID_TYPE=%s\n", type_str);
                        if (instance_str[0] != '\0')
                                printf("ID_INSTANCE=%s\n", instance_str);
                        printf("ID_BUS=usb\n");