Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Sat, 7 Dec 2002 15:48:15 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Sat, 7 Dec 2002 15:48:15 -0500 Received: from gate.mvhi.com ([195.224.96.166]:8465 "EHLO gate.mvhi.com") by vger.kernel.org with ESMTP id ; Sat, 7 Dec 2002 15:48:14 -0500 Message-ID: <15858.24662.553969.380236@server.axiom.internal> Date: Sat, 7 Dec 2002 20:55:50 +0000 (GMT) From: Peter Benie To: Alan.Cox@linux.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] [2.2] pipe_write can block even with non-blocking fd X-Mailer: VM 6.75 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid Mime-Version: 1.0 (generated by tm-edit 1.7) Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1129 Lines: 34 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/