chiark / gitweb /
udevinfo: allow -a -n <node>
[elogind.git] / udevinfo.c
index f8d0b6125af7680df269f10b07ec7bcec899e82f..6b7368119f821ae87d1b949dffc0f1fcd9fd0012 100644 (file)
@@ -91,11 +91,11 @@ static int print_device_chain(const char *devpath)
        struct sysfs_device *dev;
 
        printf("\n"
-              "udevinfo starts with the device the node belongs to and then walks up the\n"
-              "device chain, to print for every device found, all possibly useful attributes\n"
-              "in the udev key format.\n"
-              "Only attributes within one device section may be used together in one rule,\n"
-              "to match the device for which the node will be created.\n"
+              "Udevinfo starts with the device specified by the devpath and then\n"
+              "walks up the chain of parent devices. It prints for every device\n"
+              "found, all possible attributes in the udev rules key format.\n"
+              "A rule to match, can be composed by the attributes of the device\n"
+              "and the attributes from one single parent device.\n"
               "\n");
 
        dev = sysfs_device_get(devpath);
@@ -105,6 +105,7 @@ static int print_device_chain(const char *devpath)
        printf("  looking at device '%s':\n", dev->devpath);
        printf("    KERNEL==\"%s\"\n", dev->kernel_name);
        printf("    SUBSYSTEM==\"%s\"\n", dev->subsystem);
+       printf("    DRIVER==\"%s\"\n", dev->driver);
        print_all_attributes(dev->devpath);
 
        /* walk up the chain of devices */
@@ -112,7 +113,7 @@ static int print_device_chain(const char *devpath)
                dev = sysfs_device_get_parent(dev);
                if (dev == NULL)
                        break;
-               printf("  looking at device '%s':\n", dev->devpath);
+               printf("  looking at parent device '%s':\n", dev->devpath);
                printf("    ID==\"%s\"\n", dev->kernel_name);
                printf("    BUS==\"%s\"\n", dev->subsystem);
                printf("    DRIVER==\"%s\"\n", dev->driver);
@@ -375,12 +376,22 @@ int main(int argc, char *argv[], char *envp[])
                }
                break;
        case ACTION_ATTRIBUTE_WALK:
-               if (path[0] == '\0') {
-                       fprintf(stderr, "attribute walk on device chain needs path(-p) specified\n");
-                       rc = 4;
-                       goto exit;
-               } else
+               if (path[0] != '\0') {
                        print_device_chain(path);
+               } else if (name[0] != '\0') {
+                       char devpath[PATH_SIZE];
+
+                       if (udev_db_lookup_name(name, devpath, sizeof(devpath)) != 0) {
+                               fprintf(stderr, "node name not found\n");
+                               rc = 4;
+                               goto exit;
+                       }
+                       print_device_chain(devpath);
+               } else {
+                       fprintf(stderr, "attribute walk needs device path(-p) or node name(-n) specified\n");
+                       rc = 5;
+                       goto exit;
+               }
                break;
        case ACTION_ROOT:
                printf("%s\n", udev_root);