X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudev-node.c;h=100ca92903ef2baf41ff36b6a5f2326176221325;hb=310119085123384a1620f23f6bcd3b26645a70be;hp=e402dc9de38402334973b54187f7250c79e07304;hpb=1822e9b033fcd91a7dfd3b0bfd12cfbbd93fc470;p=elogind.git diff --git a/udev/udev-node.c b/udev/udev-node.c index e402dc9de..100ca9290 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -52,13 +52,13 @@ static int name_index(struct udev *udev, const char *devpath, const char *name, util_strlcat(filename, device, sizeof(filename)); if (add) { - info(udev, "creating index: '%s'\n", filename); + dbg(udev, "creating index: '%s'\n", filename); util_create_path(udev, filename); fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644); if (fd > 0) close(fd); } else { - info(udev, "removing index: '%s'\n", filename); + dbg(udev, "removing index: '%s'\n", filename); unlink(filename); util_delete_path(udev, filename); } @@ -185,7 +185,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) } else if (S_ISLNK(stats.st_mode)) { char buf[UTIL_PATH_SIZE]; - info(udev, "found existing symlink '%s'\n", slink); + dbg(udev, "found existing symlink '%s'\n", slink); len = readlink(slink, buf, sizeof(buf)); if (len > 0) { buf[len] = '\0'; @@ -241,11 +241,11 @@ static int name_index_get_devices(struct udev *udev, const char *name, struct ud util_path_encode(&dirname[start], sizeof(dirname) - start); dir = opendir(dirname); if (dir == NULL) { - info(udev, "no index directory '%s': %m\n", dirname); + dbg(udev, "no index directory '%s': %m\n", dirname); count = -1; goto out; } - info(udev, "found index directory '%s'\n", dirname); + dbg(udev, "found index directory '%s'\n", dirname); while (1) { struct dirent *ent; @@ -278,11 +278,12 @@ static int update_link(struct udev_device *dev, const char *slink, int test) int priority = 0; int rc = 0; - info(udev, "update symlink '%s' of '%s'\n", slink, udev_device_get_syspath(dev)); + dbg(udev, "update symlink '%s' of '%s'\n", slink, udev_device_get_syspath(dev)); udev_list_init(&dev_list); count = name_index_get_devices(udev, slink, &dev_list); - info(udev, "found %i devices with name '%s'\n", count, slink); + if (count > 1) + info(udev, "found %i devices with name '%s'\n", count, slink); /* if we don't have a reference, delete it */ if (count <= 0) { @@ -302,12 +303,12 @@ static int update_link(struct udev_device *dev, const char *slink, int test) const char *devnode; syspath = udev_list_entry_get_name(dev_entry); - info(udev, "found '%s' for '%s'\n", syspath, slink); + dbg(udev, "found '%s' for '%s'\n", syspath, slink); /* did we find ourself? we win, if we have the same priority */ if (strcmp(udev_device_get_syspath(dev), syspath) == 0) { - info(udev, "compare (our own) priority of '%s' %i >= %i\n", - udev_device_get_devpath(dev), udev_device_get_devlink_priority(dev), priority); + dbg(udev, "compare (our own) priority of '%s' %i >= %i\n", + udev_device_get_devpath(dev), udev_device_get_devlink_priority(dev), priority); if (strcmp(udev_device_get_devnode(dev), slink) == 0) { info(udev, "'%s' is our device node, database inconsistent, skip link update\n", udev_device_get_devnode(dev)); @@ -328,10 +329,10 @@ static int update_link(struct udev_device *dev, const char *slink, int test) info(udev, "'%s' is a device node of '%s', skip link update\n", devnode, syspath); } else { - info(udev, "compare priority of '%s' %i > %i\n", - udev_device_get_devpath(dev_db), - udev_device_get_devlink_priority(dev_db), - priority); + dbg(udev, "compare priority of '%s' %i > %i\n", + udev_device_get_devpath(dev_db), + udev_device_get_devlink_priority(dev_db), + priority); if (target[0] == '\0' || udev_device_get_devlink_priority(dev_db) > priority) { priority = udev_device_get_devlink_priority(dev_db); util_strlcpy(target, devnode, sizeof(target)); @@ -366,17 +367,30 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev /* update possible left-over symlinks */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev_old)) { + const char *name = udev_list_entry_get_name(list_entry); struct udev_list_entry *list_entry_current; + int found; + /* check if old link name is now our node name */ + if (strcmp(name, udev_device_get_devnode(dev)) == 0) + continue; + + /* check if old link name still belongs to this device */ + found = 0; udev_list_entry_foreach(list_entry_current, udev_device_get_devlinks_list_entry(dev)) { - if (strcmp(udev_list_entry_get_name(list_entry_current), - udev_list_entry_get_name(list_entry)) == 0) - continue; + const char *name_current = udev_list_entry_get_name(list_entry_current); + + if (strcmp(name, name_current) == 0) { + found = 1; + break; + } } - /* link does no longer belong to this device */ - info(udev, "update old symlink '%s' no longer belonging to '%s'\n", - udev_list_entry_get_name(list_entry), udev_device_get_devpath(dev)); - update_link(dev, udev_list_entry_get_name(list_entry), test); + if (found) + continue; + + info(udev, "update old symlink '%s' no longer belonging to '%s'\n", name, udev_device_get_devpath(dev)); + name_index(udev, udev_device_get_devpath(dev), name, 0, test); + update_link(dev, name, test); } /* @@ -431,7 +445,7 @@ int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid, in } } - /* add node and to name index */ + /* add node to name index */ name_index(udev, udev_device_get_devpath(dev), udev_device_get_devnode(dev), 1, test); /* create/update symlinks, add symlinks to name index */