summaryrefslogtreecommitdiff
path: root/udev_rules.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2005-03-13 11:40:32 +0100
committerGreg KH <gregkh@suse.de>2005-04-26 23:53:18 -0700
commit3e5958dee5f24283eb5c6a2d2d95e1a39428a3b8 (patch)
treebaa33eae18ff92944084d140b3ff6049ce826b39 /udev_rules.c
parent79f651f4bd2fb395a705792eb8ce551a6021bcd6 (diff)
[PATCH] add ENV{} key to match agains environment variables
Diffstat (limited to 'udev_rules.c')
-rw-r--r--udev_rules.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/udev_rules.c b/udev_rules.c
index d1192614aa..551c06131b 100644
--- a/udev_rules.c
+++ b/udev_rules.c
@@ -498,30 +498,6 @@ static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct
return 0;
}
-static int match_sysfs_pairs(struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
-{
- int i;
-
- for (i = 0; i < rule->sysfs_pair_count; i++) {
- struct key_pair *pair;
-
- pair = &rule->sysfs_pair[i];
- if ((pair->name[0] == '\0') || (pair->value[0] == '\0'))
- break;
- if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
- dbg("sysfs pair #%u does not match", i);
- if (pair->operation != KEY_OP_NOMATCH)
- return -1;
- } else {
- dbg("sysfs pair #%u matches", i);
- if (pair->operation == KEY_OP_NOMATCH)
- return -1;
- }
- }
-
- return 0;
-}
-
static int match_id(struct udev_rule *rule, struct sysfs_device *sysfs_device)
{
char path[PATH_SIZE];
@@ -570,6 +546,33 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule,
dbg(KEY_SUBSYSTEM " key is true");
}
+ if (rule->env_pair_count) {
+ int i;
+
+ dbg("check for " KEY_ENV " pairs");
+ for (i = 0; i < rule->env_pair_count; i++) {
+ struct key_pair *pair;
+ const char *value;
+
+ pair = &rule->env_pair[i];
+ value = getenv(pair->name);
+ if (!value) {
+ dbg(KEY_ENV "{'%s'} is not found", pair->name);
+ goto exit;
+ }
+ if (strcmp_pattern(pair->value, value) != 0) {
+ dbg(KEY_ENV "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto exit;
+ } else {
+ dbg(KEY_ENV "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto exit;
+ }
+ }
+ dbg(KEY_ENV " key is true");
+ }
+
/* walk up the chain of physical devices and find a match */
while (1) {
/* check for matching driver */
@@ -632,11 +635,23 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule,
}
/* check for matching sysfs pairs */
- if (rule->sysfs_pair[0].name[0] != '\0') {
+ if (rule->sysfs_pair_count) {
+ int i;
+
dbg("check " KEY_SYSFS " pairs");
- if (match_sysfs_pairs(rule, class_dev, sysfs_device) != 0) {
- dbg(KEY_SYSFS " is not matching");
- goto try_parent;
+ for (i = 0; i < rule->sysfs_pair_count; i++) {
+ struct key_pair *pair;
+
+ pair = &rule->sysfs_pair[i];
+ if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
+ dbg(KEY_SYSFS "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto try_parent;
+ } else {
+ dbg(KEY_SYSFS "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto try_parent;
+ }
}
dbg(KEY_SYSFS " keys are true");
}