chiark / gitweb /
rules: update Fedora
[elogind.git] / udev_rules.c
index 400ebad9e33b6841302065576e528feed81707b4..0dcbf156ea14d9708b4b53b5d9cd60b4b956e0ff 100644 (file)
@@ -597,6 +597,7 @@ void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)
                SUBST_KERNEL,
                SUBST_KERNEL_NUMBER,
                SUBST_ID,
+               SUBST_DRIVER,
                SUBST_MAJOR,
                SUBST_MINOR,
                SUBST_RESULT,
@@ -616,6 +617,7 @@ void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)
                { .name = "number",     .fmt = 'n',     .type = SUBST_KERNEL_NUMBER },
                { .name = "kernel",     .fmt = 'k',     .type = SUBST_KERNEL },
                { .name = "id",         .fmt = 'b',     .type = SUBST_ID },
+               { .name = "driver",     .fmt = 'd',     .type = SUBST_DRIVER },
                { .name = "major",      .fmt = 'M',     .type = SUBST_MAJOR },
                { .name = "minor",      .fmt = 'm',     .type = SUBST_MINOR },
                { .name = "result",     .fmt = 'c',     .type = SUBST_RESULT },
@@ -707,6 +709,12 @@ found:
                                dbg("substitute id '%s'", udev->dev_parent->kernel);
                        }
                        break;
+               case SUBST_DRIVER:
+                       if (udev->dev_parent != NULL) {
+                               strlcat(string, udev->dev_parent->driver, maxsize);
+                               dbg("substitute driver '%s'", udev->dev_parent->driver);
+                       }
+                       break;
                case SUBST_MAJOR:
                        sprintf(temp2, "%d", major(udev->devt));
                        strlcat(string, temp2, maxsize);
@@ -944,6 +952,22 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
        if (match_key("NAME", rule, &rule->name, udev->name))
                goto nomatch;
 
+       /* match against current list of symlinks */
+       if (rule->symlink_match.operation == KEY_OP_MATCH ||
+           rule->symlink_match.operation == KEY_OP_NOMATCH) {
+               struct name_entry *name_loop;
+               int match = 0;
+
+               list_for_each_entry(name_loop, &udev->symlink_list, node) {
+                       if (match_key("SYMLINK", rule, &rule->symlink_match, name_loop->name) == 0) {
+                               match = 1;
+                               break;
+                       }
+               }
+               if (!match)
+                       goto nomatch;
+       }
+
        for (i = 0; i < rule->env.count; i++) {
                struct key_pair *pair = &rule->env.keys[i];
 
@@ -979,6 +1003,14 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
                                strlcat(filename, "/", sizeof(filename));
                                strlcat(filename, attr, sizeof(filename));
                        }
+               } else if (filename[0] != '/') {
+                       char tmp[PATH_SIZE];
+
+                       strlcpy(tmp, sysfs_path, sizeof(tmp));
+                       strlcat(tmp, udev->dev->devpath, sizeof(tmp));
+                       strlcat(tmp, "/", sizeof(tmp));
+                       strlcat(tmp, filename, sizeof(tmp));
+                       strlcpy(filename, tmp, sizeof(filename));
                }
 
                match = (stat(filename, &statbuf) == 0);
@@ -1311,14 +1343,18 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev)
                        }
 
                        /* collect symlinks */
-                       if (!udev->symlink_final && rule->symlink.operation != KEY_OP_UNSET) {
+                       if (!udev->symlink_final &&
+                           (rule->symlink.operation == KEY_OP_ASSIGN ||
+                            rule->symlink.operation == KEY_OP_ASSIGN_FINAL ||
+                            rule->symlink.operation == KEY_OP_ADD)) {
                                char temp[PATH_SIZE];
                                char *pos, *next;
                                int count;
 
                                if (rule->symlink.operation == KEY_OP_ASSIGN_FINAL)
                                        udev->symlink_final = 1;
-                               if (rule->symlink.operation == KEY_OP_ASSIGN || rule->symlink.operation == KEY_OP_ASSIGN_FINAL) {
+                               if (rule->symlink.operation == KEY_OP_ASSIGN ||
+                                   rule->symlink.operation == KEY_OP_ASSIGN_FINAL) {
                                        info("reset symlink list");
                                        name_list_cleanup(&udev->symlink_list);
                                }
@@ -1401,8 +1437,8 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev)
        }
 
        if (!name_set) {
-               strlcpy(udev->name, udev->dev->kernel, sizeof(udev->name));
                info("no node name set, will use kernel name '%s'", udev->name);
+               strlcpy(udev->name, udev->dev->kernel, sizeof(udev->name));
        }
 
        if (udev->tmp_node[0] != '\0') {