[PATCH] Check we read off the compelte event from inotify

Simo Sorce idra at samba.org
Sat Sep 5 08:18:12 MDT 2009

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 |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/source3/smbd/notify_inotify.c b/source3/smbd/notify_inotify.c
index 26570a2..3872ea7 100644
--- a/source3/smbd/notify_inotify.c
+++ b/source3/smbd/notify_inotify.c
@@ -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,13 @@ 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) {
+	status = read_data(in->fd, e0, bufsize);
+	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0,("Failed to read all inotify data\n"));
+		/* the inotify fd will now be out of sync,
+		 * can't keep reading data off it */
+		TALLOC_FREE(fde);


More information about the samba-technical mailing list