diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-07-16 07:46:31 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-07-16 07:46:31 +0200 |
commit | 594dd610252923591ed0f310695e82d3fb87e581 (patch) | |
tree | 7dc290f161526aca177dfac7934842e6a6d281c1 /udev_rules_parse.c | |
parent | c609f627fae97bef5f163eb2eb993d3c8211f768 (diff) |
allow rules to have labels and skip to next label
This will allow us to have whole blocks of rules to skip
conditionally. The following section creates the node "yes":
GOTO="TEST"
NAME="no"
NAME="no2", LABEL="NO"
NAME="yes", LABEL="TEST"
NAME="no3"
Diffstat (limited to 'udev_rules_parse.c')
-rw-r--r-- | udev_rules_parse.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/udev_rules_parse.c b/udev_rules_parse.c index 7c3c2e7fc2..0259268c8f 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -52,8 +52,10 @@ struct udev_rule *udev_rules_iter_next(struct udev_rules *rules) return NULL; dbg("current=%zi", rules->current); - if (rules->current >= rules->bufsize) + if (rules->current >= rules->bufsize) { + dbg("no more rules"); return NULL; + } /* get next rule */ rule = (struct udev_rule *) (rules->buf + rules->current); @@ -62,6 +64,28 @@ struct udev_rule *udev_rules_iter_next(struct udev_rules *rules) return rule; } +struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label) +{ + static struct udev_rule *rule; + +next: + dbg("current=%zi", rules->current); + if (rules->current >= rules->bufsize) { + dbg("no more rules"); + return NULL; + } + rule = (struct udev_rule *) (rules->buf + rules->current); + + if (strcmp(&rule->buf[rule->label.val_off], label) != 0) { + dbg("moving forward, looking for label '%s'", label); + rules->current += sizeof(struct udev_rule) + rule->bufsize; + goto next; + } + + dbg("found label '%s'", label); + return rule; +} + static int get_key(char **line, char **key, enum key_operation *operation, char **value) { char *linepos; @@ -237,6 +261,18 @@ static int add_to_rules(struct udev_rules *rules, char *line) if (retval) break; + if (strcasecmp(key, "LABEL") == 0) { + add_rule_key(rule, &rule->label, operation, value); + valid = 1; + continue; + } + + if (strcasecmp(key, "GOTO") == 0) { + add_rule_key(rule, &rule->goto_label, operation, value); + valid = 1; + continue; + } + if (strcasecmp(key, "KERNEL") == 0) { add_rule_key(rule, &rule->kernel_name, operation, value); valid = 1; @@ -475,6 +511,7 @@ static int add_to_rules(struct udev_rules *rules, char *line) err("realloc failed"); goto exit; } + dbg("adding rule to offset %zi", rules->bufsize); memcpy(rules->buf + rules->bufsize, rule, rule_size); rules->bufsize += rule_size; exit: |