From: kay.sievers@vrfy.org Date: Fri, 12 Nov 2004 05:52:55 +0000 (+0100) Subject: [PATCH] support SUBSYSTEM as a rule key X-Git-Tag: 046~12 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6818c51d7abeab9914eb7193968b1efa9459a853;p=systemd [PATCH] support SUBSYSTEM as a rule key This should make it easier to catch e.g all block or net devices with a single rule. --- diff --git a/namedev.c b/namedev.c index 3ab45d4e..8bf3c0e7 100644 --- 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); diff --git a/namedev.h b/namedev.h index f1e00822..3837e864 100644 --- 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]; diff --git a/namedev_parse.c b/namedev_parse.c index 73828a83..cc02d255 100644 --- a/namedev_parse.c +++ b/namedev_parse.c @@ -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); diff --git a/test/udev-test.pl b/test/udev-test.pl index 2ba63fe8..5f6f864d 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -1102,6 +1102,17 @@ EOF exp_name => "cdrom", conf => < "SUBSYSTEM test", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + conf => <