chiark / gitweb /
udevadm: enumerate - update prev pointer properly
[elogind.git] / libudev / libudev-device-private.c
index bf93834c10a7353eb03980caa04aad46bd4b581b..3afa82e04f40b3869caf0afbb2a82daa93c71267 100644 (file)
@@ -34,8 +34,12 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add)
        util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/tags/", tag, "/", id, NULL);
 
        if (add) {
+               int fd;
+
                util_create_path(udev, filename);
-               symlink(udev_device_get_devpath(dev), filename);
+               fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
+               if (fd >= 0)
+                       close(fd);
        } else {
                unlink(filename);
        }
@@ -74,6 +78,7 @@ int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old,
 
 static bool device_has_info(struct udev_device *udev_device)
 {
+       struct udev *udev = udev_device_get_udev(udev_device);
        struct udev_list_entry *list_entry;
 
        if (udev_device_get_devlinks_list_entry(udev_device) != NULL)
@@ -85,6 +90,12 @@ static bool device_has_info(struct udev_device *udev_device)
                        return true;
        if (udev_device_get_tags_list_entry(udev_device) != NULL)
                return true;
+       if (udev_device_get_devnode(udev_device) != NULL && udev_device_get_knodename(udev_device) != NULL) {
+               size_t devlen = strlen(udev_get_dev_path(udev))+1;
+
+               if (strcmp(&udev_device_get_devnode(udev_device)[devlen], udev_device_get_knodename(udev_device)) != 0)
+                       return true;
+       }
        if (udev_device_get_watch_handle(udev_device) >= 0)
                return true;
        return false;
@@ -98,7 +109,6 @@ int udev_device_update_db(struct udev_device *udev_device)
        char filename[UTIL_PATH_SIZE];
        char filename_tmp[UTIL_PATH_SIZE];
        FILE *f;
-       size_t devlen = strlen(udev_get_dev_path(udev))+1;
 
        id = udev_device_get_id_filename(udev_device);
        if (id == NULL)
@@ -108,7 +118,9 @@ int udev_device_update_db(struct udev_device *udev_device)
        util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
 
        /* do not store anything for otherwise empty devices */
-       if (!has_info && udev_device_get_devnode(udev_device) == NULL) {
+       if (!has_info &&
+           major(udev_device_get_devnum(udev_device)) == 0 &&
+           udev_device_get_ifindex(udev_device) == 0) {
                unlink(filename);
                return 0;
        }
@@ -123,6 +135,7 @@ int udev_device_update_db(struct udev_device *udev_device)
        }
 
        if (has_info) {
+               size_t devlen = strlen(udev_get_dev_path(udev))+1;
                struct udev_list_entry *list_entry;
 
                if (udev_device_get_devnode(udev_device) != NULL) {
@@ -134,6 +147,8 @@ int udev_device_update_db(struct udev_device *udev_device)
                        fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device));
                if (udev_device_get_watch_handle(udev_device) >= 0)
                        fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device));
+               if (udev_device_get_usec_initialized(udev_device) > 0)
+                       fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device));
                udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
                        if (!udev_list_entry_get_flags(list_entry))
                                continue;