chiark / gitweb /
update SUSE rules
[elogind.git] / udev_device.c
index 84d0ab2204e262cd40f27119df3de82d5fe1109d..ab4965c3a1f35d9bde7efce763dec25e7547c229 100644 (file)
@@ -26,7 +26,8 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
-#include <stropts.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
 #include <net/if.h>
 #include <linux/sockios.h>
 
@@ -113,8 +114,12 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
        int retval = 0;
 
        /* add device node */
-       if (major(udev->devt) != 0 && strcmp(udev->action, "add") == 0) {
+       if (major(udev->devt) != 0 &&
+           (strcmp(udev->action, "add") == 0 || strcmp(udev->action, "online") == 0)) {
+               struct udevice *udev_old;
+
                dbg("device node add '%s'", udev->dev->devpath);
+
                udev_rules_get_name(rules, udev);
                if (udev->ignore_device) {
                        info("device event will be ignored");
@@ -124,10 +129,42 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
                        info("device node creation supressed");
                        goto exit;
                }
-               /* create node, store in db */
-               retval = udev_node_add(udev);
-               if (retval == 0)
+
+               /* 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) {
+                               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 */
+               retval = udev_node_add(udev, udev_old);
+               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;
        }