mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] [2.2] pipe_write can block even with non-blocking fd
@ 2002-12-07 20:55 Peter Benie
  0 siblings, 0 replies; only message in thread
From: Peter Benie @ 2002-12-07 20:55 UTC (permalink / raw)
  To: Alan.Cox; +Cc: linux-kernel

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)) {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-12-07 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-07 20:55 [PATCH] [2.2] pipe_write can block even with non-blocking fd Peter Benie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®