+
+ match = (stat(filename, &statbuf) == 0);
+ info("'%s' %s", filename, match ? "exists" : "does not exist");
+ if (match && rule->test_mode_mask > 0) {
+ match = ((statbuf.st_mode & rule->test_mode_mask) > 0);
+ info("'%s' has mode=%#o and %s %#o", filename, statbuf.st_mode,
+ match ? "matches" : "does not match",
+ rule->test_mode_mask);
+ }
+ if (match && rule->test.operation == KEY_OP_NOMATCH)
+ goto nomatch;
+ if (!match && rule->test.operation == KEY_OP_MATCH)
+ goto nomatch;
+ dbg("TEST key is true");
+ }
+
+ if (rule->wait_for_sysfs.operation != KEY_OP_UNSET) {
+ int found;
+
+ found = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
+ if (!found && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH))
+ goto nomatch;
+ }
+
+ /* check for matching sysfs attribute pairs */
+ for (i = 0; i < rule->attr.count; i++) {
+ struct key_pair *pair = &rule->attr.keys[i];
+
+ if (pair->key.operation == KEY_OP_MATCH ||
+ pair->key.operation == KEY_OP_NOMATCH) {
+ const char *key_name = key_pair_name(rule, pair);
+ const char *key_value = key_val(rule, &pair->key);
+ char devpath[PATH_SIZE];
+ char *attrib;
+ const char *value = NULL;
+ char val[VALUE_SIZE];
+ size_t len;
+
+ if (attr_get_by_subsys_id(key_name, devpath, sizeof(devpath), &attrib)) {
+ if (attrib != NULL)
+ value = sysfs_attr_get_value(devpath, attrib);
+ else
+ goto nomatch;
+ }
+ if (value == NULL)
+ value = sysfs_attr_get_value(udev->dev->devpath, key_name);
+ if (value == NULL)
+ goto nomatch;
+ strlcpy(val, value, sizeof(val));
+
+ /* strip trailing whitespace of value, if not asked to match for it */
+ len = strlen(key_value);
+ if (len > 0 && !isspace(key_value[len-1])) {
+ len = strlen(val);
+ while (len > 0 && isspace(val[len-1]))
+ val[--len] = '\0';
+ dbg("removed %zi trailing whitespace chars from '%s'", strlen(val)-len, val);
+ }
+
+ if (match_key("ATTR", rule, &pair->key, val))
+ goto nomatch;