]> err.no Git - systemd/commitdiff
[PATCH] support SUBSYSTEM as a rule key
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 12 Nov 2004 05:52:55 +0000 (06:52 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 05:25:38 +0000 (22:25 -0700)
This should make it easier to catch e.g all block or net devices with
a single rule.

namedev.c
namedev.h
namedev_parse.c
test/udev-test.pl
udev.8.in

index 3ab45d4ec6a67c32788b5b35a621a6f43ccaa193..8bf3c0e73e87ac1d702d56df0425d8cbd1339950 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -604,7 +604,7 @@ static int match_rule(struct config_device *dev, struct sysfs_class_device *clas
                        }
                }
 
-               /* check for matching kernel name*/
+               /* check for matching kernel name */
                if (dev->kernel[0] != '\0') {
                        dbg("check for " FIELD_KERNEL " dev->kernel='%s' class_dev->name='%s'", dev->kernel, class_dev->name);
                        if (strcmp_pattern(dev->kernel, class_dev->name) != 0) {
@@ -615,6 +615,17 @@ static int match_rule(struct config_device *dev, struct sysfs_class_device *clas
                        }
                }
 
+               /* check for matching subsystem */
+               if (dev->subsystem[0] != '\0') {
+                       dbg("check for " FIELD_SUBSYSTEM " dev->subsystem='%s' class_dev->name='%s'", dev->subsystem, class_dev->name);
+                       if (strcmp_pattern(dev->subsystem, udev->subsystem) != 0) {
+                               dbg(FIELD_SUBSYSTEM " is not matching");
+                               goto try_parent;
+                       } else {
+                               dbg(FIELD_SUBSYSTEM " matches");
+                       }
+               }
+
                /* check for matching bus id */
                if (dev->id[0] != '\0') {
                        dbg("check " FIELD_ID);
index f1e0082241e8f611aeb9a637bd54e6cb90f05267..3837e864a0049e4c70d2f60f0c3c9ecd8deebe64 100644 (file)
--- a/namedev.h
+++ b/namedev.h
@@ -42,6 +42,7 @@ struct sysfs_class_device;
 #define FIELD_PROGRAM          "PROGRAM"
 #define FIELD_RESULT           "RESULT"
 #define FIELD_KERNEL           "KERNEL"
+#define FIELD_SUBSYSTEM                "SUBSYSTEM"
 #define FIELD_NAME             "NAME"
 #define FIELD_SYMLINK          "SYMLINK"
 #define FIELD_OWNER            "OWNER"
@@ -78,6 +79,7 @@ struct config_device {
        char kernel[NAME_SIZE];
        char program[PROGRAM_SIZE];
        char result[PROGRAM_SIZE];
+       char subsystem[SUBSYSTEM_SIZE];
        char name[NAME_SIZE];
        char symlink[NAME_SIZE];
        struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
index 73828a83b2f864d436c222d1085779db74bacd78..cc02d255556fea76c052f1755f6cbb70a65fdce3 100644 (file)
@@ -258,6 +258,12 @@ static int namedev_parse_rules(const char *filename, void *data)
                                continue;
                        }
 
+                       if (strcasecmp(temp2, FIELD_SUBSYSTEM) == 0) {
+                               strfieldcpy(dev.subsystem, temp3);
+                               valid = 1;
+                               continue;
+                       }
+
                        if (strcasecmp(temp2, FIELD_PROGRAM) == 0) {
                                program_given = 1;
                                strfieldcpy(dev.program, temp3);
index 2ba63fe83fe61f5f0271c636cddba878e73b4285..5f6f864df2f137aff9cf6321dd53154e60b7b7bf 100644 (file)
@@ -1102,6 +1102,17 @@ EOF
                exp_name        => "cdrom",
                conf            => <<EOF
 KERNEL="sda", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "SUBSYSTEM test",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", NAME="should_not_match", SUBSYSTEM="vc"
+BUS="scsi", KERNEL="sda", NAME="node", SUBSYSTEM="block"
+BUS="scsi", KERNEL="sda", NAME="should_not_match2", SUBSYSTEM="vc"
 EOF
        },
 );
index 168842d4358450e1ca98adae830f6cc94018263d..14a28d8dc2eb5daf77fddc606ebb10cc4058d80b 100644 (file)
--- a/udev.8.in
+++ b/udev.8.in
@@ -171,6 +171,10 @@ Match the bus type of the device.
 .B KERNEL
 Match the kernel device name.
 .TP
+.B SUBSYSTEM
+Match the kernel's subsystem name.
+.TP
+.TP
 .B ID
 Match the device number on the bus, like PCI bus id.
 .TP