X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_rules.c;h=596bcd188bc28064d49330bb3248b9b036d00948;hp=e9b32df1c66d85a838a311f160ae889955d0f90e;hb=90cd961e2cb660b6c3ed9c9a33e8878f8aaa163c;hpb=f8db897faaaf3417ed0a31a39c7f47cc8cf40bd6 diff --git a/udev_rules.c b/udev_rules.c index e9b32df1c..596bcd188 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -290,6 +290,12 @@ static int find_free_number(const char *base, const char *devpath) char filename[PATH_SIZE]; struct udevice *udev_db; int num = 0; + static int warn = 1; + + if (warn) { + err("%%e is deprecated, will be removed and is unlikely to work correctly. Don't use it."); + warn = 0; + } /* check if the device already owns a matching name */ udev_db = udev_device_init(); @@ -342,23 +348,33 @@ out: #define WAIT_LOOP_PER_SECOND 50 static int wait_for_sysfs(struct udevice *udev, const char *file, int timeout) { - char filename[PATH_SIZE]; + char devicepath[PATH_SIZE]; + char filepath[PATH_SIZE]; struct stat stats; int loop = timeout * WAIT_LOOP_PER_SECOND; - snprintf(filename, sizeof(filename), "%s%s/%s", sysfs_path, udev->dev->devpath, file); - filename[sizeof(filename)-1] = '\0'; - dbg("will wait %i sec for '%s'", timeout, filename); + strlcpy(devicepath, sysfs_path, sizeof(devicepath)); + strlcat(devicepath, udev->dev->devpath, sizeof(devicepath)); + strlcpy(filepath, devicepath, sizeof(filepath)); + strlcat(filepath, "/", sizeof(filepath)); + strlcat(filepath, file, sizeof(filepath)); + dbg("will wait %i sec for '%s'", timeout, filepath); while (--loop) { - if (stat(filename, &stats) == 0) { - info("file '%s' appeared after %i loops", filename, (timeout * WAIT_LOOP_PER_SECOND) - loop-1); + /* lookup file */ + if (stat(filepath, &stats) == 0) { + info("file '%s' appeared after %i loops", filepath, (timeout * WAIT_LOOP_PER_SECOND) - loop-1); return 0; } - info("wait for '%s' for %i mseconds", filename, 1000 / WAIT_LOOP_PER_SECOND); + /* make sure the device does not have disappeared in the meantime */ + if (stat(devicepath, &stats) != 0) { + info("device disappeared while waiting for '%s'", filepath); + return -2; + } + info("wait for '%s' for %i mseconds", filepath, 1000 / WAIT_LOOP_PER_SECOND); usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND); } - err("waiting for '%s' failed", filename); + err("waiting for '%s' failed", filepath); return -1; } @@ -594,7 +610,7 @@ found: snprintf(udev->tmp_node, sizeof(udev->tmp_node), "%s/.tmp-%u-%u", udev_root, major(udev->devt), minor(udev->devt)); udev->tmp_node[sizeof(udev->tmp_node)-1] = '\0'; - udev_make_node(udev, udev->tmp_node, udev->devt, 0600, 0, 0); + udev_node_mknod(udev, udev->tmp_node, udev->devt, 0600, 0, 0); } strlcat(string, udev->tmp_node, maxsize); dbg("substitute temporary device node name '%s'", udev->tmp_node); @@ -606,6 +622,13 @@ found: case SUBST_MODALIAS: { const char *value; + static int warn = 1; + + if (warn) { + err("$modalias is deprecated, use $env{MODALIAS} or " + "$sysfs{modalias} instead."); + warn = 0; + } value = sysfs_attr_get_value(udev->dev->devpath, "modalias"); if (value != NULL) { @@ -657,7 +680,8 @@ static int match_key(const char *key_name, struct udev_rule *rule, struct key *k char *key_value; char *pos; - if (key->operation == KEY_OP_UNSET) + if (key->operation != KEY_OP_MATCH && + key->operation != KEY_OP_NOMATCH) return 0; strlcpy(value, rule->buf + key->val_off, sizeof(value)); @@ -703,8 +727,18 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule) if (match_key("DEVPATH", rule, &rule->devpath, udev->dev->devpath)) goto nomatch; + /* compare NAME against a previously assigned value */ + if (match_key("NAME", rule, &rule->name, udev->name)) + goto nomatch; + if (rule->modalias.operation != KEY_OP_UNSET) { const char *value; + static int warn = 1; + + if (warn) { + err("MODALIAS is deprecated, use ENV{MODALIAS} or SYSFS{modalias} instead."); + warn = 0; + } value = sysfs_attr_get_value(udev->dev->devpath, "modalias"); if (value == NULL) { @@ -719,7 +753,8 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule) struct key_pair *pair = &rule->env.keys[i]; /* we only check for matches, assignments will be handled later */ - if (pair->key.operation != KEY_OP_ASSIGN) { + if (pair->key.operation == KEY_OP_MATCH || + pair->key.operation == KEY_OP_NOMATCH) { const char *key_name = key_pair_name(rule, pair); const char *value = getenv(key_name); @@ -746,22 +781,16 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule) udev->dev_parent = udev->dev; while (1) { /* check for matching driver */ - if (rule->driver.operation != KEY_OP_UNSET) { - if (match_key("DRIVER", rule, &rule->driver, udev->dev_parent->driver)) - goto try_parent; - } + if (match_key("DRIVER", rule, &rule->driver, udev->dev_parent->driver)) + goto try_parent; /* check for matching subsystem/bus value */ - if (rule->bus.operation != KEY_OP_UNSET) { - if (match_key("BUS", rule, &rule->bus, udev->dev_parent->subsystem)) - goto try_parent; - } + if (match_key("BUS", rule, &rule->bus, udev->dev_parent->subsystem)) + goto try_parent; /* check for matching bus id (device name) */ - if (rule->id.operation != KEY_OP_UNSET) { - if (match_key("ID", rule, &rule->id, udev->dev_parent->kernel_name)) - goto try_parent; - } + if (match_key("ID", rule, &rule->id, udev->dev_parent->kernel_name)) + goto try_parent; /* check for matching sysfs pairs */ if (rule->sysfs.count) { @@ -874,10 +903,13 @@ try_parent: if (pair->key.operation == KEY_OP_ASSIGN) { const char *key_name = key_pair_name(rule, pair); const char *value = key_val(rule, &pair->key); + char *key_value = name_list_key_add(&udev->env_list, key_name, value); + if (key_value == NULL) + break; - name_list_key_add(&udev->env_list, key_name, value); - setenv(key_name, value, 1); - dbg("export ENV '%s=%s'", key_name, value); + udev_rules_apply_format(udev, key_value, NAME_SIZE); + putenv(key_value); + dbg("export ENV '%s'", key_value); } } @@ -902,7 +934,10 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev) if (rule == NULL) break; - if (name_set && rule->name.operation != KEY_OP_UNSET) { + if (name_set && + (rule->name.operation == KEY_OP_ASSIGN || + rule->name.operation == KEY_OP_ASSIGN_FINAL || + rule->name.operation == KEY_OP_ADD)) { dbg("node name already set, rule ignored"); continue; } @@ -988,7 +1023,9 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev) } /* set name, later rules with name set will be ignored */ - if (rule->name.operation != KEY_OP_UNSET) { + if (rule->name.operation == KEY_OP_ASSIGN || + rule->name.operation == KEY_OP_ASSIGN_FINAL || + rule->name.operation == KEY_OP_ADD) { int count; name_set = 1;