Check we read off the compelte event from inotify
authorSimo Sorce <idra@samba.org>
Sat, 5 Sep 2009 14:18:12 +0000 (10:18 -0400)
committerJeremy Allison <jra@samba.org>
Mon, 7 Sep 2009 16:29:04 +0000 (09:29 -0700)
The kernel may return a short read, so we must use read_data() to make sure we
read off the full buffer. If somethign bad happens we also need to kill the
inotify watch because the filedescriptor will return out of sync structures if
we read only part of the data.

source3/smbd/notify_inotify.c

index 26570a22162d5facef1536216dec317934c7b326..61599456c6d9adb08413c775f3684d3602d59b49 100644 (file)
@@ -232,6 +232,7 @@ static void inotify_handler(struct event_context *ev, struct fd_event *fde,
        int bufsize = 0;
        struct inotify_event *e0, *e;
        uint32_t prev_cookie=0;
+       NTSTATUS status;
 
        /*
          we must use FIONREAD as we cannot predict the length of the
@@ -248,9 +249,14 @@ static void inotify_handler(struct event_context *ev, struct fd_event *fde,
        e0 = e = (struct inotify_event *)TALLOC_SIZE(in, bufsize);
        if (e == NULL) return;
 
-       if (sys_read(in->fd, e0, bufsize) != bufsize) {
-               DEBUG(0,("Failed to read all inotify data\n"));
+       status = read_data(in->fd, (char *)e0, bufsize);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Failed to read all inotify data - %s\n",
+                       nt_errstr(status)));
                talloc_free(e0);
+               /* the inotify fd will now be out of sync,
+                * can't keep reading data off it */
+               TALLOC_FREE(fde);
                return;
        }