chiark / gitweb /
match KEY="A|B" without temporary string copy
authorKay Sievers <kay.sievers@vrfy.org>
Sat, 25 Oct 2008 01:00:03 +0000 (03:00 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Sat, 25 Oct 2008 01:00:03 +0000 (03:00 +0200)
test/udev-test.pl
udev/udev-rules.c

index 9725aff5ba0a245ca7881787e1f68d0f2792e26e..f630b74a9d859247ed96ab3ed38e282e15d0577d 100755 (executable)
@@ -1448,6 +1448,31 @@ EOF
 KERNEL=="dontknow*|*nothing", NAME="nomatch"
 KERNEL=="ttyACM*", NAME="before"
 KERNEL=="dontknow*|ttyACM*|nothing*", NAME="right"
 KERNEL=="dontknow*|*nothing", NAME="nomatch"
 KERNEL=="ttyACM*", NAME="before"
 KERNEL=="dontknow*|ttyACM*|nothing*", NAME="right"
+EOF
+       },
+       {
+               desc            => "test multi matches 3",
+               subsys          => "tty",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
+               exp_name        => "right",
+               rules           => <<EOF
+KERNEL=="dontknow|nothing", NAME="nomatch"
+KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong1"
+KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong2"
+KERNEL=="dontknow|ttyACM0|nothing", NAME="right"
+EOF
+       },
+       {
+               desc            => "test multi matches 4",
+               subsys          => "tty",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
+               exp_name        => "right",
+               rules           => <<EOF
+KERNEL=="dontknow|nothing", NAME="nomatch"
+KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong1"
+KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong2"
+KERNEL=="all|dontknow|ttyACM0", NAME="right"
+KERNEL=="ttyACM0a|nothing", NAME="wrong3"
 EOF
        },
        {
 EOF
        },
        {
index 0643811d7a458809bf6d5e517f0f55dd4d8f886d..8c0e1d961b4618c99c05c63f7b5f7f0ab72e0f03 100644 (file)
@@ -1726,21 +1726,26 @@ static int match_key(struct udev_rules *rules, struct token *token, const char *
                break;
        case GL_SPLIT:
                {
                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", token_str[token->type], 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;
                                        break;
-                               key_value = pos;
+                               }
+                               split = &next[1];
                        }
                        break;
                }
                        }
                        break;
                }