chiark / gitweb /
Cleanup a little.
[elogind.git] / udev / udev-watch.c
index 24df481cf88e94c6f01aa03dd550abdf0936bb81..33b493d512f5afd60d351f9e65033c8619f7fc0c 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
  * Copyright (C) 2009 Canonical Ltd.
+ * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -102,21 +103,16 @@ void udev_watch_restore(struct udev *udev)
 
                        buf[len] = '\0';
                        dbg(udev, "old watch to '%s' found\n", buf);
-
                        dev = udev_device_new_from_syspath(udev, buf);
                        if (dev == NULL) {
                                unlink(path);
                                continue;
                        }
 
-                       udev_device_read_db(dev);
-                       udev_device_set_info_loaded(dev);
-
                        info(udev, "restoring old watch on '%s'\n", udev_device_get_devnode(dev));
                        udev_watch_begin(udev, dev);
 
                        udev_device_unref(dev);
-
                        unlink(path);
                }
 
@@ -146,10 +142,10 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev)
        const char *filename;
        int wd;
 
-       if (inotify_fd < 0)
+       if (inotify_fd < 0 || major(udev_device_get_devnum(dev)) == 0)
                return;
 
-       wd = inotify_add_watch (inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
+       wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
        if (wd < 0) {
                err(udev, "inotify_add_watch(%d, %s, %o) failed: %m\n",
                    inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
@@ -167,6 +163,9 @@ void udev_watch_clear(struct udev *udev, struct udev_device *dev)
        DIR *dir;
        struct dirent *ent;
 
+       if (inotify_fd < 0 || major(udev_device_get_devnum(dev)) == 0)
+               return;
+
        util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
        util_strlcat(filename, "/.udev/watch", sizeof(filename));