[PATCH] [2.2] pipe_write can block even with non-blocking fd

From: Peter Benie (peterb@chiark.greenend.org.uk)
Date: Sat Dec 07 2002 - 15:55:50 EST


Please apply the following patch. This makes non-blocking writes to
pipe actually non-blocking.

A program that demonstrates the bug can be found at:
http://www.chiark.greenend.org.uk/~peterb/linux/nonblock/pipe-testnonblock.c

--- 2.2.19/fs/pipe.c.orig Thu Dec 6 21:20:38 2001
+++ 2.2.19/fs/pipe.c Thu Dec 6 21:22:47 2001
@@ -105,9 +105,17 @@
         else
                 free = 1; /* can't do it atomically, wait for any free space */
         up(&inode->i_sem);
- if (down_interruptible(&inode->i_atomic_write)) {
- down(&inode->i_sem);
- return -ERESTARTSYS;
+ if (filp->f_flags & O_NONBLOCK) {
+ if (down_trylock(&inode->i_atomic_write)) {
+ down(&inode->i_sem);
+ return -ERESTARTSYS;
+ }
+ }
+ else {
+ if (down_interruptible(&inode->i_atomic_write)) {
+ down(&inode->i_sem);
+ return -ERESTARTSYS;
+ }
         }
         while (count>0) {
                 while ((PIPE_FREE(*inode) < free) || PIPE_LOCK(*inode)) {
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Dec 07 2002 - 22:00:30 EST