+ /* find the device with the highest priority */
+ list_for_each_entry(device, &name_list, node) {
+ info("found '%s' for '%s'\n", device->name, name);
+
+ /* did we find ourself? we win, if we have the same priority */
+ if (strcmp(udev->dev->devpath, device->name) == 0) {
+ info("compare (our own) priority of '%s' %i >= %i\n",
+ udev->dev->devpath, udev->link_priority, priority);
+ if (strcmp(udev->name, name) == 0) {
+ info("'%s' is our device node, database inconsistent, skip link update\n", udev->name);
+ } else if (target[0] == '\0' || udev->link_priority >= priority) {
+ priority = udev->link_priority;
+ strlcpy(target, udev->name, sizeof(target));
+ }
+ continue;
+ }
+
+ /* another device, read priority from database */
+ udev_db = udev_device_init(NULL);
+ if (udev_db == NULL)
+ continue;
+ if (udev_db_get_device(udev_db, device->name) == 0) {
+ if (strcmp(udev_db->name, name) == 0) {
+ info("'%s' is a device node of '%s', skip link update\n", udev_db->name, device->name);
+ } else {
+ info("compare priority of '%s' %i > %i\n",
+ udev_db->dev->devpath, udev_db->link_priority, priority);
+ if (target[0] == '\0' || udev_db->link_priority > priority) {
+ priority = udev_db->link_priority;
+ strlcpy(target, udev_db->name, sizeof(target));
+ }
+ }
+ }
+ udev_device_cleanup(udev_db);
+ }
+ name_list_cleanup(&name_list);
+
+ if (target[0] == '\0') {
+ info("no current target for '%s' found\n", name);
+ rc = 1;
+ goto out;
+ }
+
+ /* create symlink to the target with the highest priority */
+ strlcpy(node, udev_root, sizeof(node));
+ strlcat(node, "/", sizeof(node));
+ strlcat(node, target, sizeof(node));
+ info("'%s' with target '%s' has the highest priority %i, create it\n", name, target, priority);
+ if (!udev->test_run) {
+ create_path(slink);
+ node_symlink(node, slink);
+ }
+out:
+ return rc;