On Tue, Mar 01, 2005 at 01:37:23AM +0100, Andrea Arcangeli wrote:
I'm going to update a semi-productive system running twisted servers using processes too, with the new pipe_poll code too to see what happens (that's the good thing of not being fully productive yet, so I can experiment a bit more ;).
System is up and running fine with this patch against 2.6.8 that should apply to most l-k out there, matching latest 2.6.11. This will bring linux in sync with the twisted expectations of "r && w" meaning 'reader disconnected' with select, it'll change the behaviour of poll not to return POLLIN set unconditionally, and more specifically it'll never return POLLIN for a WRONLY fd, and it'll never return POLLOUT for a RDONLY fd. --- x/fs/pipe.c.~1~ 2004-08-25 02:47:51.000000000 +0200 +++ x/fs/pipe.c 2005-03-01 02:10:50.000000000 +0100 @@ -300,14 +300,18 @@ pipe_poll(struct file *filp, poll_table poll_wait(filp, PIPE_WAIT(*inode), wait); - /* Reading only -- no need for acquiring the semaphore. */ - mask = POLLIN | POLLRDNORM; - if (PIPE_EMPTY(*inode)) - mask = POLLOUT | POLLWRNORM; - if (!PIPE_WRITERS(*inode) && filp->f_version != PIPE_WCOUNTER(*inode)) - mask |= POLLHUP; - if (!PIPE_READERS(*inode)) - mask |= POLLERR; + mask = 0; + if (filp->f_mode & FMODE_READ) { + mask |= PIPE_LEN(*inode) ? POLLIN | POLLRDNORM : 0; + if (!PIPE_WRITERS(*inode) && filp->f_version != PIPE_WCOUNTER(*inode)) + mask |= POLLHUP; + } + + if (filp->f_mode & FMODE_WRITE) { + mask |= PIPE_EMPTY(*inode) ? POLLOUT | POLLWRNORM : 0; + if (!PIPE_READERS(*inode)) + mask |= POLLERR; + } return mask; }