chiark / gitweb /
rules: fix typo
[elogind.git] / libudev / libudev-device-private.c
index bf93834c10a7353eb03980caa04aad46bd4b581b..b78b6c9553503b61e0c9aa07731c6ce2b894b2da 100644 (file)
@@ -31,11 +31,15 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add)
        id = udev_device_get_id_filename(dev);
        if (id == NULL)
                return;
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/tags/", tag, "/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(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)
@@ -81,10 +86,16 @@ static bool device_has_info(struct udev_device *udev_device)
        if (udev_device_get_devlink_priority(udev_device) != 0)
                return true;
        udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device))
-               if (udev_list_entry_get_flags(list_entry))
+               if (udev_list_entry_get_num(list_entry))
                        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,17 +109,18 @@ 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)
                return -1;
 
        has_info = device_has_info(udev_device);
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", 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;
        }
@@ -122,7 +134,15 @@ int udev_device_update_db(struct udev_device *udev_device)
                return -1;
        }
 
+       /*
+        * set 'sticky' bit to indicate that we should not clean the
+        * database when we transition from initramfs to the real root
+        */
+       if (udev_device_get_db_persist(udev_device))
+               fchmod(fileno(f), 01644);
+
        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,8 +154,10 @@ 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))
+                       if (!udev_list_entry_get_num(list_entry))
                                continue;
                        fprintf(f, "E:%s=%s\n",
                                udev_list_entry_get_name(list_entry),
@@ -161,7 +183,7 @@ int udev_device_delete_db(struct udev_device *udev_device)
        id = udev_device_get_id_filename(udev_device);
        if (id == NULL)
                return -1;
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
        unlink(filename);
        return 0;
 }