Timo Sirainen wrote:
On Mon, 2006-01-23 at 18:50 +0100, Vaclav Haisman wrote:
I have attached patch that should fix all kqueue issues (I hope). It is smaller than it looks because I also reindented both kqueue files with tabs as is the rest of the source.
if ((fds[fd].mode & (IO_READ | IO_ERROR)) == 0 && (fcntl(io->fd, F_GETFD, 0) != -1 || errno != EBADF)) if (kevent(ctx->kq, &ev, 1, NULL, 0, NULL) == -1) {
Can't this be fixed some other way so that those EBADFs don't happen? If not, is it guaranteed that it gives EBADF, and not accidentally succeed because some other fd was just opened with same number as io->fd?
Also can't the above just as well be written as:
if ((fds[fd].mode & (IO_READ | IO_ERROR)) == 0) if (kevent(ctx->kq, &ev, 1, NULL, 0, NULL) == -1 && errno != EBADF) { The nature of kqueue is that it automatically removes/unregisters all filters associated with handle if the handle is closed and thus if the user of the ioloop code tries to remove the handle after it has been already closed then he gets EBADF.
I think the way you wrote it actually looks better.
The other attached patch is what I used for easier debugging. I think it could help somebody else too.
I've tried to keep the error messages as unique as needed so that file names and numbers wouldn't be needed :) But I'll add it to http://dovecot.org/patches/ in case it's needed some day by someone.
Vaclav Haisman