[dovecot-cvs] dovecot/src/lib ioloop-poll.c,1.31,1.32

cras at dovecot.org cras at dovecot.org
Sun Jan 29 14:21:08 EET 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv28341/lib

Modified Files:
	ioloop-poll.c 
Log Message:
If DEBUG is enabled, make sure the fd is still open when removing the I/O
handler.



Index: ioloop-poll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-poll.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- ioloop-poll.c	13 Jan 2006 20:26:01 -0000	1.31
+++ ioloop-poll.c	29 Jan 2006 12:21:06 -0000	1.32
@@ -7,6 +7,7 @@
 
 #ifdef IOLOOP_POLL
 
+#include <fcntl.h>
 #include <sys/poll.h>
 
 #ifndef INITIAL_POLL_FDS
@@ -107,6 +108,19 @@
 	index = ctx->fd_index[fd];
 	i_assert(index >= 0 && (unsigned int) index < ctx->fds_count);
 
+#ifdef DEBUG
+	/* io_remove() is required to be called before fd is closed.
+	   This is required by kqueue, but since poll is more commonly used
+	   while developing, this check here should catch the error early
+	   enough not to cause problems for kqueue users. */
+	if (fcntl(io->fd, F_GETFD, 0) < 0) {
+		if (errno == EBADF)
+			i_panic("io_remove(%d) called too late", io->fd);
+		else
+			i_error("fcntl(%d, F_GETFD) failed: %m", io->fd);
+	}
+#endif
+
 	if (condition & IO_READ) {
 		ctx->fds[index].events &= ~(POLLIN|POLLPRI);
 		ctx->fds[index].revents &= ~(POLLIN|POLLPRI);



More information about the dovecot-cvs mailing list