chiark / gitweb /
Look at more inotify events in the buffer than just the first.
[elogind.git] / udev / udevd.c
index 5fb6d5f7345e2fc38425fb4b6b70e0a2cadbb1e5..cfc091b699067e7d2e47214880b85ef9feb99d2f 100644 (file)
@@ -216,7 +216,15 @@ static void event_fork(struct udev_event *event)
                alarm(UDEV_EVENT_TIMEOUT);
 
                /* clear any existing udev watch on the node */
-               udev_watch_end(event->udev, event->dev);
+               if (inotify_fd != -1) {
+                       struct udev_device *dev_old;
+
+                       dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(event->dev));
+                       if (dev_old != NULL) {
+                               udev_watch_end(event->udev, dev_old);
+                               udev_device_unref(dev_old);
+                       }
+               }
 
                /* apply rules, create node, symlinks */
                err = udev_event_execute_rules(event, rules);
@@ -232,7 +240,6 @@ static void event_fork(struct udev_event *event)
                /* apply/restore inotify watch */
                if (err == 0 && event->inotify_watch &&
                    strcmp(udev_device_get_action(event->dev), "remove") != 0)
-                       info(event->udev, "device will be watched for changes\n");
                        udev_watch_begin(event->udev, event->dev);
 
                info(event->udev, "seq %llu exit with %i\n", udev_device_get_seqnum(event->dev), err);
@@ -539,10 +546,16 @@ static int handle_inotify(struct udev *udev)
 
        read(inotify_fd, buf, nbytes);
 
-       for (pos = 0, ev = (struct inotify_event *)(buf + pos); pos < nbytes; pos += sizeof(struct inotify_event) + ev->len) {
+       for (pos = 0; pos < nbytes; pos += sizeof(struct inotify_event) + ev->len) {
                struct udev_device *dev;
 
-               dbg(udev, "inotify event: %x for %d (%s)\n", ev->mask, ev->wd, ev->len ? ev->name : "*");
+               ev = (struct inotify_event *)(buf + pos);
+               if (ev->len) {
+                       dbg(udev, "inotify event: %x for %s\n", ev->mask, ev->name);
+                       reload_config = 1;
+                       continue;
+               }
+
                dev = udev_watch_lookup(udev, ev->wd);
                if (dev != NULL) {
                        dbg(udev, "inotify event: %x for %s\n", ev->mask, udev_device_get_devnode(dev));
@@ -562,9 +575,8 @@ static int handle_inotify(struct udev *udev)
                                udev_watch_end(udev, dev);
 
                        udev_device_unref(dev);
-               } else {
-                       reload_config = 1;
                }
+
        }
 
        free (buf);