summaryrefslogtreecommitdiff
path: root/udev_device.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2006-06-14 16:32:52 +0200
committerKay Sievers <kay.sievers@suse.de>2006-06-14 16:32:52 +0200
commitfa33d857e2cdd65d3de2f88021ecacf167fc21f0 (patch)
tree0267347e95dcf04ae57df4baa0054d7502f7cb5b /udev_device.c
parentafb66e32335d7bea55b015855089df4779916829 (diff)
don't remove symlinks if they are already there
Consecutive "add" events will not remove and recreate the same symlinks anymore. No longer valid links, like after changing a filesystem label, will still be removed.
Diffstat (limited to 'udev_device.c')
-rw-r--r--udev_device.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/udev_device.c b/udev_device.c
index 6dc843ed22..a7a8b13c96 100644
--- a/udev_device.c
+++ b/udev_device.c
@@ -132,17 +132,38 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
/* read current database entry, we may want to cleanup symlinks */
udev_old = udev_device_init();
if (udev_old != NULL) {
- if (udev_db_get_device(udev_old, udev->dev->devpath) == 0) {
- info("device '%s' already known, remove possible symlinks", udev->dev->devpath);
- udev_node_remove_symlinks(udev_old);
- }
- udev_device_cleanup(udev_old);
+ if (udev_db_get_device(udev_old, udev->dev->devpath) != 0) {
+ udev_device_cleanup(udev_old);
+ udev_old = NULL;
+ } else
+ info("device '%s' already in database, validate currently present symlinks",
+ udev->dev->devpath);
}
- /* create node and symlinks, store record in database */
+ /* create node and symlinks */
retval = udev_node_add(udev, udev_old);
- if (retval == 0)
+ if (retval == 0) {
+ /* store record in database */
udev_db_add_device(udev);
+
+ /* remove possibly left-over symlinks */
+ if (udev_old != NULL) {
+ struct name_entry *link_loop;
+ struct name_entry *link_old_loop;
+ struct name_entry *link_old_tmp_loop;
+
+ /* remove still valid symlinks from old list */
+ list_for_each_entry_safe(link_old_loop, link_old_tmp_loop, &udev_old->symlink_list, node)
+ list_for_each_entry(link_loop, &udev->symlink_list, node)
+ if (strcmp(link_old_loop->name, link_loop->name) == 0) {
+ dbg("symlink '%s' still valid, keep it", link_old_loop->name);
+ list_del(&link_old_loop->node);
+ free(link_old_loop);
+ }
+ udev_node_remove_symlinks(udev_old);
+ udev_device_cleanup(udev_old);
+ }
+ }
goto exit;
}