diff options
author | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2008-09-09 00:09:49 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-09-09 00:09:49 +0200 |
commit | df7ae680d88f77ff67f44a49c57dd0079b527a60 (patch) | |
tree | fcc06b46c493b733dd2d9fde6f9c7aa9a7cdf9ce /udev/udev_rules_parse.c | |
parent | a035bf274477689920bcac12792b28de9d35ab6c (diff) |
threadsafe rules iteration
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>
Diffstat (limited to 'udev/udev_rules_parse.c')
-rw-r--r-- | udev/udev_rules_parse.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/udev/udev_rules_parse.c b/udev/udev_rules_parse.c index df7b57ba54..81f0edb6f5 100644 --- a/udev/udev_rules_parse.c +++ b/udev/udev_rules_parse.c @@ -33,49 +33,53 @@ #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; + rules = iter->rules; 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 */ - 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; } -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; - size_t start = rules->current; + struct udev_rules *rules = iter->rules; + size_t start = iter->current; 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); - rules->current = start; + iter->current = start; 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); - rules->current += sizeof(struct udev_rule) + rule->bufsize; + iter->current += sizeof(struct udev_rule) + rule->bufsize; goto next; } |