X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_rules_parse.c;h=3ada8b1c7d14c5bbc19d71857609ed1668e1771f;hb=655a8acf920cd43356003b4499e545a7b2fcc402;hp=b586df13241270ebafbb6e7f301410efc71afe3b;hpb=c70560feef0eb61a150cd2f956f0beead4313ffe;p=elogind.git diff --git a/udev_rules_parse.c b/udev_rules_parse.c index b586df132..3ada8b1c7 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -60,11 +60,13 @@ struct udev_rule *udev_rules_iter_next(struct udev_rules *rules) struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label) { static struct udev_rule *rule; + size_t start = rules->current; next: dbg("current=%zi\n", rules->current); if (rules->current >= rules->bufsize) { - dbg("no more rules\n"); + err("LABEL='%s' not found, GOTO will be ignored\n", label); + rules->current = start; return NULL; } rule = (struct udev_rule *) (rules->buf + rules->current); @@ -245,6 +247,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena memset(buf, 0x00, sizeof(buf)); rule = (struct udev_rule *) buf; + rule->event_timeout = -1; linepos = line; valid = 0; @@ -494,8 +497,8 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena continue; } - if (strcasecmp(key, "WAIT_FOR_SYSFS") == 0) { - add_rule_key(rule, &rule->wait_for_sysfs, operation, value); + if (strcasecmp(key, "WAIT_FOR") == 0 || strcasecmp(key, "WAIT_FOR_SYSFS") == 0) { + add_rule_key(rule, &rule->wait_for, operation, value); valid = 1; continue; } @@ -604,6 +607,11 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena rule->link_priority = atoi(&pos[strlen("link_priority=")]); dbg("link priority=%i\n", rule->link_priority); } + pos = strstr(value, "event_timeout="); + if (pos != NULL) { + rule->event_timeout = atoi(&pos[strlen("event_timeout=")]); + dbg("event timout=%i\n", rule->event_timeout); + } pos = strstr(value, "string_escape="); if (pos != NULL) { pos = &pos[strlen("string_escape=")]; @@ -623,7 +631,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena err("unknown key '%s' in %s:%u\n", key, filename, lineno); } - if (physdev && rule->wait_for_sysfs.operation == KEY_OP_UNSET) + if (physdev && rule->wait_for.operation == KEY_OP_UNSET) err("PHYSDEV* values are deprecated and will be removed from a future kernel, \n" "please fix it in %s:%u", filename, lineno); @@ -721,53 +729,53 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names) struct stat statbuf; char filename[PATH_MAX]; LIST_HEAD(name_list); - LIST_HEAD(dyn_list); + LIST_HEAD(sort_list); struct name_entry *name_loop, *name_tmp; - struct name_entry *dyn_loop, *dyn_tmp; + struct name_entry *sort_loop, *sort_tmp; int retval = 0; memset(rules, 0x00, sizeof(struct udev_rules)); rules->resolve_names = resolve_names; - /* read main config from single file or all files in a directory */ - if (stat(udev_rules_dir, &statbuf) != 0) - return -1; - if ((statbuf.st_mode & S_IFMT) != S_IFDIR) { - dbg("parse single rules file '%s'\n", udev_rules_dir); - name_list_add(&name_list, udev_rules_dir, 1); + if (udev_rules_dir[0] != '\0') { + /* custom rules location for testing */ + add_matching_files(&name_list, udev_rules_dir, RULESFILE_SUFFIX); } else { - dbg("parse rules directory '%s'\n", udev_rules_dir); - retval = add_matching_files(&name_list, udev_rules_dir, RULESFILE_SUFFIX); - } - - /* read dynamic rules directory */ - strlcpy(filename, udev_root, sizeof(filename)); - strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename)); - if (stat(filename, &statbuf) != 0) { - create_path(filename); - selinux_setfscreatecon(filename, NULL, S_IFDIR|0755); - mkdir(filename, 0755); - selinux_resetfscreatecon(); - } - add_matching_files(&dyn_list, filename, RULESFILE_SUFFIX); + /* read default rules */ + add_matching_files(&name_list, RULES_LIB_DIR, RULESFILE_SUFFIX); + + /* read user/custom rules */ + add_matching_files(&sort_list, RULES_ETC_DIR, RULESFILE_SUFFIX); + + /* read dynamic/temporary rules */ + strlcpy(filename, udev_root, sizeof(filename)); + strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename)); + if (stat(filename, &statbuf) != 0) { + create_path(filename); + selinux_setfscreatecon(filename, NULL, S_IFDIR|0755); + mkdir(filename, 0755); + selinux_resetfscreatecon(); + } + add_matching_files(&sort_list, filename, RULESFILE_SUFFIX); - /* sort dynamic rules files by basename into list of files */ - list_for_each_entry_safe(dyn_loop, dyn_tmp, &dyn_list, node) { - const char *dyn_base = strrchr(dyn_loop->name, '/'); + /* sort all rules files by basename into list of files */ + list_for_each_entry_safe(sort_loop, sort_tmp, &sort_list, node) { + const char *sort_base = strrchr(sort_loop->name, '/'); - if (dyn_base == NULL) - continue; + if (sort_base == NULL) + continue; - list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) { - const char *name_base = strrchr(name_loop->name, '/'); + list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) { + const char *name_base = strrchr(name_loop->name, '/'); - if (name_base == NULL) - continue; + if (name_base == NULL) + continue; - if (strcmp(name_base, dyn_base) > 0) - break; + if (strcmp(name_base, sort_base) > 0) + break; + } + list_move_tail(&sort_loop->node, &name_loop->node); } - list_move_tail(&dyn_loop->node, &name_loop->node); } /* parse list of files */