chiark / gitweb /
threadsafe rules iteration
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>
Mon, 8 Sep 2008 22:09:49 +0000 (00:09 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Mon, 8 Sep 2008 22:09:49 +0000 (00:09 +0200)
Move ->current out of "struct udev_rules" and into a new "struct udev_rules_iter".

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
udev/udev_rules.c
udev/udev_rules.h
udev/udev_rules_parse.c

index ce1f66e..004a89f 100644 (file)
@@ -1368,6 +1368,7 @@ nomatch:
 
 int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
 {
 
 int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
 {
+       struct udev_rules_iter iter;
        struct udev_rule *rule;
        int name_set = 0;
 
        struct udev_rule *rule;
        int name_set = 0;
 
@@ -1375,9 +1376,9 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
        dbg(udevice->udev, "udevice->dev->kernel='%s'\n", udevice->dev->kernel);
 
        /* look for a matching rule to apply */
        dbg(udevice->udev, "udevice->dev->kernel='%s'\n", udevice->dev->kernel);
 
        /* look for a matching rule to apply */
-       udev_rules_iter_init(rules);
+       udev_rules_iter_init(&iter, rules);
        while (1) {
        while (1) {
-               rule = udev_rules_iter_next(rules);
+               rule = udev_rules_iter_next(&iter);
                if (rule == NULL)
                        break;
 
                if (rule == NULL)
                        break;
 
@@ -1530,7 +1531,7 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
 
                        if (rule->goto_label.operation != KEY_OP_UNSET) {
                                dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
 
                        if (rule->goto_label.operation != KEY_OP_UNSET) {
                                dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
-                               udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+                               udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));
                        }
                }
        }
                        }
                }
        }
@@ -1551,14 +1552,15 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
 
 int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice)
 {
 
 int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice)
 {
+       struct udev_rules_iter iter;
        struct udev_rule *rule;
 
        dbg(udevice->udev, "udevice->kernel='%s'\n", udevice->dev->kernel);
 
        /* look for a matching rule to apply */
        struct udev_rule *rule;
 
        dbg(udevice->udev, "udevice->kernel='%s'\n", udevice->dev->kernel);
 
        /* look for a matching rule to apply */
-       udev_rules_iter_init(rules);
+       udev_rules_iter_init(&iter, rules);
        while (1) {
        while (1) {
-               rule = udev_rules_iter_next(rules);
+               rule = udev_rules_iter_next(&iter);
                if (rule == NULL)
                        break;
 
                if (rule == NULL)
                        break;
 
@@ -1609,7 +1611,7 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice)
 
                        if (rule->goto_label.operation != KEY_OP_UNSET) {
                                dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
 
                        if (rule->goto_label.operation != KEY_OP_UNSET) {
                                dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
-                               udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+                               udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));
                        }
                }
        }
                        }
                }
        }
index 4f95121..b2e5d57 100644 (file)
@@ -111,16 +111,20 @@ struct udev_rules {
        struct udev *udev;
        char *buf;
        size_t bufsize;
        struct udev *udev;
        char *buf;
        size_t bufsize;
-       size_t current;
        int resolve_names;
 };
 
        int resolve_names;
 };
 
+struct udev_rules_iter {
+       struct udev_rules *rules;
+       size_t current;
+};
+
 extern int udev_rules_init(struct udev *udev, struct udev_rules *rules, int resolve_names);
 extern void udev_rules_cleanup(struct udev_rules *rules);
 
 extern int udev_rules_init(struct udev *udev, struct udev_rules *rules, int resolve_names);
 extern void udev_rules_cleanup(struct udev_rules *rules);
 
-extern void udev_rules_iter_init(struct udev_rules *rules);
-extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules);
-extern struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label);
+extern void udev_rules_iter_init(struct udev_rules_iter *iter, struct udev_rules *rules);
+extern struct udev_rule *udev_rules_iter_next(struct udev_rules_iter *iter);
+extern struct udev_rule *udev_rules_iter_label(struct udev_rules_iter *iter, const char *label);
 
 extern int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev);
 extern int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev);
 
 extern int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev);
 extern int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev);
index df7b57b..81f0edb 100644 (file)
 #include "udev_selinux.h"
 
 
 #include "udev_selinux.h"
 
 
-void udev_rules_iter_init(struct udev_rules *rules)
+void udev_rules_iter_init(struct udev_rules_iter *iter, struct udev_rules *rules)
 {
 {
-       dbg(rules->udev, "bufsize=%zi\n", rules->bufsize);
-       rules->current = 0;
+       dbg(iter->rules->udev, "bufsize=%zi\n", rules->bufsize);
+       iter->rules = rules;
+       iter->current = 0;
 }
 
 }
 
-struct udev_rule *udev_rules_iter_next(struct udev_rules *rules)
+struct udev_rule *udev_rules_iter_next(struct udev_rules_iter *iter)
 {
 {
+       struct udev_rules *rules;
        struct udev_rule *rule;
 
        struct udev_rule *rule;
 
+       rules = iter->rules;
        if (!rules)
                return NULL;
 
        if (!rules)
                return NULL;
 
-       dbg(rules->udev, "current=%zi\n", rules->current);
-       if (rules->current >= rules->bufsize) {
-               dbg(rules->udev, "no more rules\n");
+       dbg(iter->rules->udev, "current=%zi\n", iter->current);
+       if (iter->current >= rules->bufsize) {
+               dbg(iter->rules->udev, "no more rules\n");
                return NULL;
        }
 
        /* get next rule */
                return NULL;
        }
 
        /* get next rule */
-       rule = (struct udev_rule *) (rules->buf + rules->current);
-       rules->current += sizeof(struct udev_rule) + rule->bufsize;
+       rule = (struct udev_rule *) (rules->buf + iter->current);
+       iter->current += sizeof(struct udev_rule) + rule->bufsize;
 
        return rule;
 }
 
 
        return rule;
 }
 
-struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label)
+struct udev_rule *udev_rules_iter_label(struct udev_rules_iter *iter, const char *label)
 {
        struct udev_rule *rule;
 {
        struct udev_rule *rule;
-       size_t start = rules->current;
+       struct udev_rules *rules = iter->rules;
+       size_t start = iter->current;
 
 next:
 
 next:
-       dbg(rules->udev, "current=%zi\n", rules->current);
-       if (rules->current >= rules->bufsize) {
+       dbg(iter->rules->udev, "current=%zi\n", iter->current);
+       if (iter->current >= rules->bufsize) {
                err(rules->udev, "LABEL='%s' not found, GOTO will be ignored\n", label);
                err(rules->udev, "LABEL='%s' not found, GOTO will be ignored\n", label);
-               rules->current = start;
+               iter->current = start;
                return NULL;
        }
                return NULL;
        }
-       rule = (struct udev_rule *) (rules->buf + rules->current);
+       rule = (struct udev_rule *) (rules->buf + iter->current);
 
        if (strcmp(&rule->buf[rule->label.val_off], label) != 0) {
                dbg(rules->udev, "moving forward, looking for label '%s'\n", label);
 
        if (strcmp(&rule->buf[rule->label.val_off], label) != 0) {
                dbg(rules->udev, "moving forward, looking for label '%s'\n", label);
-               rules->current += sizeof(struct udev_rule) + rule->bufsize;
+               iter->current += sizeof(struct udev_rule) + rule->bufsize;
                goto next;
        }
 
                goto next;
        }