chiark / gitweb /
add m4/ subdir
[elogind.git] / udev / udevd.c
index d93781f411dfe07d73be21a629934078a810eaa2..ee3d6f50338600db3608ce4d49a8408bc62b3c19 100644 (file)
@@ -226,6 +226,12 @@ static void event_fork(struct udev_event *event)
                if (err == 0 && !event->ignore_device && udev_get_run(event->udev))
                        udev_event_execute_run(event);
 
+               /* apply/restore inotify watch */
+               if (err == 0 && event->inotify_watch) {
+                       udev_watch_begin(event->udev, event->dev);
+                       udev_device_update_db(event->dev);
+               }
+
                info(event->udev, "seq %llu exit with %i\n", udev_device_get_seqnum(event->dev), err);
                logging_close();
                if (err != 0)
@@ -516,7 +522,6 @@ static int handle_inotify(struct udev *udev)
        int nbytes, pos;
        char *buf;
        struct inotify_event *ev;
-       int reload_config = 0;
 
        if ((ioctl(inotify_fd, FIONREAD, &nbytes) < 0) || (nbytes <= 0))
                return 0;
@@ -531,20 +536,25 @@ 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) {
-               const char *syspath;
+       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;
+               }
 
-               syspath = udev_watch_lookup(udev, ev->wd);
-               if (syspath != NULL) {
-                       dbg(udev, "inotify event: %x for %s\n", ev->mask, syspath);
+               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));
                        if (ev->mask & IN_CLOSE_WRITE) {
                                char filename[UTIL_PATH_SIZE];
                                int fd;
 
-                               info(udev, "device %s closed, synthesising write\n", syspath);
-                               util_strlcpy(filename, syspath, sizeof(filename));
+                               info(udev, "device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev));
+                               util_strlcpy(filename, udev_device_get_syspath(dev), sizeof(filename));
                                util_strlcat(filename, "/uevent", sizeof(filename));
                                fd = open(filename, O_WRONLY);
                                if (fd < 0 || write(fd, "change", 6) < 0)
@@ -552,14 +562,15 @@ static int handle_inotify(struct udev *udev)
                                close(fd);
                        }
                        if (ev->mask & IN_IGNORED)
-                               udev_watch_end(udev, ev->wd);
-               } else {
-                       reload_config = 1;
+                               udev_watch_end(udev, dev);
+
+                       udev_device_unref(dev);
                }
+
        }
 
        free (buf);
-       return reload_config;
+       return 0;
 }
 
 static void asmlinkage sig_handler(int signum)
@@ -985,7 +996,7 @@ int main(int argc, char *argv[])
 
                /* rules directory inotify watch */
                if (inotify_poll && (inotify_poll->revents & POLLIN))
-                       reload_config = handle_inotify(udev);
+                       handle_inotify(udev);
 
 handle_signals:
                signal_received = 0;