X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_rules_parse.c;h=e665957b81c652ac007d18871c3caaadf2c240a2;hp=c4c684d05927a8d4aa9e880a968bdb57f12705ca;hb=05bd6efb41b6a80378cc4f6e7427a302b4953541;hpb=79f651f4bd2fb395a705792eb8ce551a6021bcd6 diff --git a/udev_rules_parse.c b/udev_rules_parse.c index c4c684d05..e665957b8 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -157,7 +157,7 @@ static char *get_key_attribute(char *str) attr++; pos = strchr(attr, '}'); if (pos == NULL) { - dbg("missing closing brace for format"); + err("missing closing brace for format"); return NULL; } pos[0] = '\0'; @@ -168,7 +168,7 @@ static char *get_key_attribute(char *str) return NULL; } -static int rules_parse(struct udevice *udev, const char *filename) +static int rules_parse(const char *filename) { char line[LINE_SIZE]; char *bufline; @@ -185,7 +185,7 @@ static int rules_parse(struct udevice *udev, const char *filename) struct udev_rule rule; if (file_map(filename, &buf, &bufsize) != 0) { - dbg("can't open '%s' as rules file", filename); + err("can't open '%s' as rules file", filename); return -1; } dbg("reading '%s' as rules file", filename); @@ -236,7 +236,7 @@ static int rules_parse(struct udevice *udev, const char *filename) while (1) { char *key; char *value; - enum key_operation operation = KEY_OP_UNKNOWN; + enum key_operation operation = KEY_OP_UNSET; retval = get_key(&linepos, &key, &operation, &value); if (retval) @@ -256,6 +256,13 @@ static int rules_parse(struct udevice *udev, const char *filename) continue; } + if (strcasecmp(key, KEY_ACTION) == 0) { + strlcpy(rule.action, value, sizeof(rule.action)); + rule.action_operation = operation; + valid = 1; + continue; + } + if (strcasecmp(key, KEY_BUS) == 0) { strlcpy(rule.bus, value, sizeof(rule.bus)); rule.bus_operation = operation; @@ -274,20 +281,40 @@ static int rules_parse(struct udevice *udev, const char *filename) struct key_pair *pair; if (rule.sysfs_pair_count >= KEY_SYSFS_PAIRS_MAX) { - dbg("skip rule, to many " KEY_SYSFS " keys in a single rule"); + err("skip rule, to many " KEY_SYSFS " keys in a single rule"); goto error; } pair = &rule.sysfs_pair[rule.sysfs_pair_count]; + attr = get_key_attribute(key + sizeof(KEY_SYSFS)-1); + if (attr == NULL) { + err("error parsing " KEY_SYSFS " attribute"); + goto error; + } + strlcpy(pair->name, attr, sizeof(pair->name)); + strlcpy(pair->value, value, sizeof(pair->value)); + pair->operation = operation; rule.sysfs_pair_count++; + valid = 1; + continue; + } - attr = get_key_attribute(key + sizeof(KEY_SYSFS)-1); + if (strncasecmp(key, KEY_ENV, sizeof(KEY_ENV)-1) == 0) { + struct key_pair *pair; + + if (rule.env_pair_count >= KEY_ENV_PAIRS_MAX) { + err("skip rule, to many " KEY_ENV " keys in a single rule"); + goto error; + } + pair = &rule.env_pair[rule.env_pair_count]; + attr = get_key_attribute(key + sizeof(KEY_ENV)-1); if (attr == NULL) { - dbg("error parsing " KEY_SYSFS " attribute"); + err("error parsing " KEY_ENV " attribute"); continue; } strlcpy(pair->name, attr, sizeof(pair->name)); strlcpy(pair->value, value, sizeof(pair->value)); pair->operation = operation; + rule.env_pair_count++; valid = 1; continue; } @@ -359,6 +386,12 @@ static int rules_parse(struct udevice *udev, const char *filename) continue; } + if (strcasecmp(key, KEY_RUN) == 0) { + strlcpy(rule.run, value, sizeof(rule.run)); + valid = 1; + continue; + } + if (strcasecmp(key, KEY_OPTIONS) == 0) { if (strstr(value, OPTION_LAST_RULE) != NULL) { dbg("last rule to be applied"); @@ -380,7 +413,7 @@ static int rules_parse(struct udevice *udev, const char *filename) continue; } - dbg("unknown key '%s'", key); + err("unknown key '%s'", key); goto error; } @@ -388,16 +421,8 @@ static int rules_parse(struct udevice *udev, const char *filename) if (!valid) goto error; - /* simple plausibility checks for given keys */ - if ((rule.sysfs_pair[0].name[0] == '\0') ^ - (rule.sysfs_pair[0].value[0] == '\0')) { - info("inconsistency in " KEY_SYSFS " key"); - goto error; - } - if ((rule.result[0] != '\0') && (program_given == 0)) { - info(KEY_RESULT " is only useful when " - KEY_PROGRAM " is called in any rule before"); + info(KEY_RESULT " is only useful when " KEY_PROGRAM " is called in any rule before"); goto error; } @@ -408,7 +433,7 @@ static int rules_parse(struct udevice *udev, const char *filename) dbg("add_config_dev returned with error %d", retval); continue; error: - info("parse error %s, line %d:%d, rule skipped", + err("parse error %s, line %d:%d, rule skipped", filename, lineno, (int) (linepos - line)); } } @@ -426,9 +451,18 @@ int udev_rules_init(void) return -1; if ((stats.st_mode & S_IFMT) != S_IFDIR) - retval = rules_parse(NULL, udev_rules_filename); - else - retval = call_foreach_file(rules_parse, NULL, udev_rules_filename, RULEFILE_SUFFIX); + retval = rules_parse(udev_rules_filename); + else { + struct name_entry *name_loop, *name_tmp; + LIST_HEAD(name_list); + + retval = add_matching_files(&name_list, udev_rules_filename, RULEFILE_SUFFIX); + + list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) { + rules_parse(name_loop->name); + list_del(&name_loop->node); + } + } return retval; }