chiark / gitweb /
fix typo in error message
[elogind.git] / udev_rules.c
index 90dc0243fe6f8a27041ca363bff80ad9d9804017..623ca468584dce0f38a58c389141265baac51675 100644 (file)
@@ -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("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 %i mseconds", 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) {
@@ -705,6 +728,12 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
 
        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) {
@@ -733,19 +762,13 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
        }
 
        if (rule->wait_for_sysfs.operation != KEY_OP_UNSET) {
-               int match;
+               int found;
 
-               match = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
-               if (match && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) {
-                       dbg("WAIT_FOR_SYSFS is true (matching value)");
-                       return 0;
-               }
-               if (!match && (rule->wait_for_sysfs.operation == KEY_OP_NOMATCH)) {
-                       dbg("WAIT_FOR_SYSFS is true, (non matching value)");
-                       return 0;
+               found = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
+               if (!found && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) {
+                       dbg("WAIT_FOR_SYSFS failed");
+                       goto nomatch;
                }
-               dbg("WAIT_FOR_SYSFS is false");
-               return -1;
        }
 
        /* walk up the chain of parent devices and find a match */
@@ -781,6 +804,8 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
                                size_t len;
 
                                value = sysfs_attr_get_value(udev->dev_parent->devpath, key_name);
+                               if (value == NULL)
+                                       value = sysfs_attr_get_value(udev->dev->devpath, key_name);
                                if (value == NULL)
                                        goto try_parent;
                                strlcpy(val, value, sizeof(val));
@@ -994,6 +1019,7 @@ 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) {
                                int count;
+
                                name_set = 1;
                                strlcpy(udev->name, key_val(rule, &rule->name), sizeof(udev->name));
                                udev_rules_apply_format(udev, udev->name, sizeof(udev->name));
@@ -1008,17 +1034,14 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev)
                        }
 
                        if (!udev->run_final && rule->run.operation != KEY_OP_UNSET) {
-                               char program[PATH_SIZE];
-
                                if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
                                        udev->run_final = 1;
                                if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
                                        info("reset run list");
                                        name_list_cleanup(&udev->run_list);
                                }
-                               strlcpy(program, key_val(rule, &rule->run), sizeof(program));
-                               dbg("add run '%s'", program);
-                               name_list_add(&udev->run_list, program, 0);
+                               dbg("add run '%s'", key_val(rule, &rule->run));
+                               name_list_add(&udev->run_list, key_val(rule, &rule->run), 0);
                        }
 
                        if (rule->last_rule) {
@@ -1075,16 +1098,12 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev)
                        }
 
                        if (!udev->run_final && rule->run.operation != KEY_OP_UNSET) {
-                               char program[PATH_SIZE];
-
                                if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
                                        info("reset run list");
                                        name_list_cleanup(&udev->run_list);
                                }
-                               strlcpy(program, key_val(rule, &rule->run), sizeof(program));
-                               udev_rules_apply_format(udev, program, sizeof(program));
-                               dbg("add run '%s'", program);
-                               name_list_add(&udev->run_list, program, 0);
+                               dbg("add run '%s'", key_val(rule, &rule->run));
+                               name_list_add(&udev->run_list, key_val(rule, &rule->run), 0);
                                if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
                                        break;
                        }