X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudev-rules.c;h=44b26906b48465d8cfe3de3583d14933f8c59223;hb=cd94c04c518fffbf7f2c173952d77414a5d6bb6b;hp=5a2ae1af8237cae967cf62381c968fbb7635434b;hpb=db463fd3091ac9077c32ed9530b061a92d62b126;p=elogind.git diff --git a/udev/udev-rules.c b/udev/udev-rules.c index 5a2ae1af8..44b26906b 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -65,6 +65,7 @@ enum string_glob_type { GL_FORMAT, }; +#ifdef DEBUG static const char *string_glob_str[] = { [GL_UNSET] = "UNSET", [GL_PLAIN] = "plain", @@ -74,6 +75,7 @@ static const char *string_glob_str[] = { [GL_SOMETHING] = "split-glob", [GL_FORMAT] = "format", }; +#endif /* tokens of a rule are sorted/handled in this order */ enum token_type { @@ -941,6 +943,7 @@ static void dump_token(struct udev_rules *rules, struct token *token) dbg(rules->udev, "* %s\n", token_str[type]); break; case TK_M_PARENTS_MAX: + case TK_M_MAX: case TK_UNSET: dbg(rules->udev, "unknown type %u\n", type); break; @@ -1707,7 +1710,6 @@ void udev_rules_unref(struct udev_rules *rules) static int match_key(struct udev_rules *rules, struct token *token, const char *val) { - const char *key_name = token_str[token->type]; char *key_value = &rules->buf[token->key.value_off]; char *pos; int match = 0; @@ -1724,21 +1726,26 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * break; case GL_SPLIT: { - char value[UTIL_PATH_SIZE]; + const char *split; + size_t len; - util_strlcpy(value, &rules->buf[token->key.value_off], sizeof(value)); - key_value = value; - while (key_value != NULL) { - pos = strchr(key_value, '|'); - if (pos != NULL) { - pos[0] = '\0'; - pos = &pos[1]; - } - dbg(rules->udev, "match %s '%s' <-> '%s'\n", key_name, key_value, val); - match = (strcmp(key_value, val) == 0); - if (match) + split = &rules->buf[token->key.value_off]; + len = strlen(val); + while (1) { + const char *next; + + next = strchr(split, '|'); + if (next != NULL) { + size_t matchlen = (size_t)(next - split); + + match = (matchlen == len && strncmp(split, val, matchlen) == 0); + if (match) + break; + } else { + match = (strcmp(split, val) == 0); break; - key_value = pos; + } + split = &next[1]; } break; } @@ -1754,7 +1761,7 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * pos[0] = '\0'; pos = &pos[1]; } - dbg(rules->udev, "match %s '%s' <-> '%s'\n", key_name, key_value, val); + dbg(rules->udev, "match %s '%s' <-> '%s'\n", token_str[token->type], key_value, val); match = (fnmatch(key_value, val, 0) == 0); if (match) break; @@ -1771,14 +1778,14 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * } if (match && (token->key.op == OP_MATCH)) { - dbg(rules->udev, "%s is true (matching value)\n", key_name); + dbg(rules->udev, "%s is true (matching value)\n", token_str[token->type]); return 0; } if (!match && (token->key.op == OP_NOMATCH)) { - dbg(rules->udev, "%s is true (non-matching value)\n", key_name); + dbg(rules->udev, "%s is true (non-matching value)\n", token_str[token->type]); return 0; } - dbg(rules->udev, "%s is not true\n", key_name); + dbg(rules->udev, "%s is not true\n", token_str[token->type]); return -1; } @@ -1787,10 +1794,11 @@ static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct char attr[UTIL_PATH_SIZE]; const char *key_name = &rules->buf[cur->key.attr_off]; const char *key_value = &rules->buf[cur->key.value_off]; - char value[UTIL_NAME_SIZE] = ""; + char value[UTIL_NAME_SIZE]; size_t len; util_strlcpy(attr, key_name, sizeof(attr)); + util_strlcpy(value, "", sizeof(value)); util_resolve_subsys_kernel(event->udev, attr, value, sizeof(value), 1); if (value[0] == '\0') { const char *val; @@ -1823,6 +1831,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event { struct token *cur; struct token *rule; + enum escape_type esc = ESCAPE_UNSET; if (rules->tokens == NULL) return -1; @@ -1831,7 +1840,6 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event cur = &rules->tokens[0]; rule = cur; while (cur != NULL && cur->type != TK_END) { - enum escape_type esc = ESCAPE_UNSET; unsigned int idx; dump_token(rules, cur);