X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_rules.c;h=f09d6d47bfbdc8a0b0e1e238283a445c619c0dfc;hp=d1192614aa25488928f64ed94848673493a65383;hb=d6d1a18d7245b8065df95775c6d45fe2d8f2e66a;hpb=79f651f4bd2fb395a705792eb8ce551a6021bcd6 diff --git a/udev_rules.c b/udev_rules.c index d1192614a..f09d6d47b 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -498,45 +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]; - char *temp; - - strlcpy(path, sysfs_device->path, sizeof(path)); - temp = strrchr(path, '/'); - temp++; - dbg("search '%s' in '%s', path='%s'", rule->id, temp, path); - if (strcmp_pattern(rule->id, temp) != 0) - return -ENODEV; - - return 0; -} - static int match_rule(struct udevice *udev, struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device) { @@ -570,6 +531,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 */ @@ -619,7 +607,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, goto try_parent; } dbg("check " KEY_ID); - if (match_id(rule, sysfs_device) != 0) { + if (strcmp_pattern(rule->id, sysfs_device->bus_id) != 0) { dbg(KEY_ID " is not matching"); if (rule->id_operation != KEY_OP_NOMATCH) goto try_parent; @@ -632,11 +620,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"); }