# Fix the problem "described" at:
#
#   http://dovecot.org/pipermail/dovecot/2006-August/015656.html
#   http://dovecot.org/pipermail/dovecot/2006-August/015749.html
#
# This problem can be easily triggered: open a telnet session to your
# imap server, login, select inbox, enter idle mode, create a file
# inside your Maildir/new/ directory, and watch the cpu spin.
#
# -- Rui Lopes (rgl ruilopes com)
--- src/lib/ioloop-notify-kqueue.c.orig	Sat Aug 26 00:37:47 2006
+++ src/lib/ioloop-notify-kqueue.c	Sat Aug 26 01:24:56 2006
@@ -111,7 +111,10 @@
 	io->callback = callback;
 	io->context = context;
 
-	EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD,
+	/* EV_CLEAR flag is needed because the EVFILT_VNODE filter reports
+	 * event state transitions and not the current state.  With this flag,
+	 * the same event is only returned once. */
+	EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR,
 	       NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_REVOKE, 0, io);
 	if (kevent(ctx->kq, &ev, 1, NULL, 0, NULL) < 0) {
 		i_error("kevent(%d, %s) for notify failed: %m", fd, path);
