]> git.hungrycats.org Git - linux/commitdiff
Make pipe "poll()" take direction of pipe into account.
authorLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 28 Feb 2005 00:36:14 +0000 (16:36 -0800)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 28 Feb 2005 00:36:14 +0000 (16:36 -0800)
The pipe code has traditionally not cared about which end-point of the
pipe you are polling, meaning that if you poll the write-only end of a
pipe, it will still set the "this pipe is readable" bits if there is
data to be read on the read side.

That makes no sense, and together with the new bigger buffers breaks
python-twisted.

Based on debugging/patch by Andrea Arcangeli and testcase from
Thomas Crhak

fs/pipe.c

index a4932d971fe170b6b12c45fa25d2a4be5ee47799..0f9aa2bf1ad1062f73afe1a59cb9cb62936f2df0 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -398,13 +398,18 @@ pipe_poll(struct file *filp, poll_table *wait)
 
        /* Reading only -- no need for acquiring the semaphore.  */
        nrbufs = info->nrbufs;
-       mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
-       mask |= (nrbufs < PIPE_BUFFERS) ? POLLOUT | POLLWRNORM : 0;
+       mask = 0;
+       if (filp->f_mode & FMODE_READ) {
+               mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
+               if (!PIPE_WRITERS(*inode) && filp->f_version != PIPE_WCOUNTER(*inode))
+                       mask |= POLLHUP;
+       }
 
-       if (!PIPE_WRITERS(*inode) && filp->f_version != PIPE_WCOUNTER(*inode))
-               mask |= POLLHUP;
-       if (!PIPE_READERS(*inode))
-               mask |= POLLERR;
+       if (filp->f_mode & FMODE_WRITE) {
+               mask |= (nrbufs < PIPE_BUFFERS) ? POLLOUT | POLLWRNORM : 0;
+               if (!PIPE_READERS(*inode))
+                       mask |= POLLERR;
+       }
 
        return mask;
 }