]> err.no Git - systemd/commitdiff
allow multiple values to be matched with KEY=="value1|value2"
authorKay Sievers <kay.sievers@suse.de>
Tue, 12 Jul 2005 10:52:56 +0000 (12:52 +0200)
committerKay Sievers <kay.sievers@suse.de>
Tue, 12 Jul 2005 10:52:56 +0000 (12:52 +0200)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
test/udev-test.pl
udev_rules.c

index 873780d70af521552850c7eeae893026a5546914..e8cb7c48a9d8659061d9773cab4becf77f03026d 100755 (executable)
@@ -1450,6 +1450,27 @@ EOF
 KERNEL=="ttyUSB[0-9]*", NAME="right"
 KERNEL=="ttyUSB[0-9]*", NAME=""
 KERNEL=="ttyUSB[0-9]*", NAME="wrong"
+EOF
+       },
+       {
+               desc            => "test multi matches",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "right",
+               rules           => <<EOF
+KERNEL=="ttyUSB*|nothing", NAME="right"
+KERNEL=="ttyUSB*", NAME="wrong"
+EOF
+       },
+       {
+               desc            => "test multi matches 2",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "right",
+               rules           => <<EOF
+KERNEL=="dontknow*|*nothing", NAME="nomatch"
+KERNEL=="dontknow*|ttyUSB*|nothing*", NAME="right"
+KERNEL=="ttyUSB*", NAME="wrong"
 EOF
        },
 );
index 77b97d7f99de9469bc03bbacaa2f625ad28d9147..8ec8fc54a4f15a23fd5e62896bbb77a29303c863 100644 (file)
@@ -635,25 +635,36 @@ static char *key_pair_name(struct udev_rule *rule, struct key_pair *pair)
 static int match_key(const char *key_name, struct udev_rule *rule, struct key *key, const char *val)
 {
        int match;
+       char value[PATH_SIZE];
        char *key_value;
+       char *pos;
 
        if (key->operation == KEY_OP_UNSET)
                return 0;
 
-       key_value = rule->buf + key->val_off;
+       strlcpy(value, rule->buf + key->val_off, sizeof(value));
+       key_value = value;
 
-       dbg("check for %s '%s' <-> '%s'", key_name, key_value, val);
-       match = (strcmp_pattern(key_value, val) == 0);
-       if (match && (key->operation != KEY_OP_NOMATCH)) {
-               dbg("%s is matching (matching value)", key_name);
-               return 0;
-       }
-       if (!match && (key->operation == KEY_OP_NOMATCH)) {
-               dbg("%s is matching, (non matching value)", key_name);
-               return 0;
+       dbg("key %s value='%s'", key_name, key_value);
+       while (key_value) {
+               pos = strchr(key_value, '|');
+               if (pos) {
+                       pos[0] = '\0';
+                       pos++;
+               }
+               dbg("match %s '%s' <-> '%s'", key_name, key_value, val);
+               match = (strcmp_pattern(key_value, val) == 0);
+               if (match && (key->operation != KEY_OP_NOMATCH)) {
+                       dbg("%s is true (matching value)", key_name);
+                       return 0;
+               }
+               if (!match && (key->operation == KEY_OP_NOMATCH)) {
+                       dbg("%s is true (non-matching value)", key_name);
+                       return 0;
+               }
+               key_value = pos;
        }
-
-       dbg("%s is not matching", key_name);
+       dbg("%s is false", key_name);
        return -1;
 }
 
@@ -709,14 +720,14 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule,
 
                match = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
                if (match && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) {
-                       dbg("WAIT_FOR_SYSFS is matching (matching value)");
+                       dbg("WAIT_FOR_SYSFS is true (matching value)");
                        return 0;
                }
                if (!match && (rule->wait_for_sysfs.operation == KEY_OP_NOMATCH)) {
-                       dbg("WAIT_FOR_SYSFS is matching, (non matching value)");
+                       dbg("WAIT_FOR_SYSFS is true, (non matching value)");
                        return 0;
                }
-               dbg("WAIT_FOR_SYSFS is not matching");
+               dbg("WAIT_FOR_SYSFS is false");
                return -1;
        }
 
@@ -826,7 +837,7 @@ try_parent:
                apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
                dbg("check for PROGRAM program='%s", program);
                if (execute_program(program, udev->subsystem, result, sizeof(result), NULL) != 0) {
-                       dbg("PROGRAM is not matching");
+                       dbg("PROGRAM is false");
                        if (rule->program.operation != KEY_OP_NOMATCH)
                                goto exit;
                } else {