]> granicus.if.org Git - cronie/commitdiff
Cronie disables inotify support when the /etc/crontab file does not exist at startup.
authorMarcela Mašláňová <mmaslano@redhat.com>
Thu, 28 Apr 2011 08:32:17 +0000 (10:32 +0200)
committerMarcela Mašláňová <mmaslano@redhat.com>
Thu, 28 Apr 2011 08:32:17 +0000 (10:32 +0200)
Existence of crontab and directories wasn't controlled before creating
inotify watches.

src/cron.c

index b8d8456027274946dd7650aeffc78496defa1ae7..df45f447be37b725ad1b92aaffab56a28fa77f0b 100644 (file)
@@ -87,21 +87,22 @@ void set_cron_watched(int fd) {
        for (i = 0; i < sizeof (wd) / sizeof (wd[0]); ++i) {
                int w;
 
-               w = inotify_add_watch(fd, watchpaths[i],
-                       IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO |
-                       IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
-               if (w < 0) {
-                       if (wd[i] != -1) {
-                               log_it("CRON", pid, "This directory or file can't be watched",
-                                       watchpaths[i], errno);
-                               log_it("CRON", pid, "INFO", "running without inotify support",
-                                       0);
+               if (open(watchpaths[i], O_RDONLY | O_NONBLOCK, 0) != -1) {
+                       w = inotify_add_watch(fd, watchpaths[i],
+                               IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO |
+                               IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
+                       if (w < 0) {
+                               if (wd[i] != -1) {
+                                       log_it("CRON", pid, "This directory or file can't be watched",
+                                               watchpaths[i], errno);
+                                       log_it("CRON", pid, "INFO", "running without inotify support", 0);
+                               }
+                               inotify_enabled = 0;
+                               set_cron_unwatched(fd);
+                               return;
                        }
-                       inotify_enabled = 0;
-                       set_cron_unwatched(fd);
-                       return;
+                       wd[i] = w;
                }
-               wd[i] = w;
        }
 
        if (!inotify_enabled) {