From nobody@FreeBSD.org  Wed Feb 22 01:04:22 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E31C716A473
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Feb 2006 01:04:22 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C013943D45
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Feb 2006 01:04:22 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k1M14M6F063745
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Feb 2006 01:04:22 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k1M14MZi063744;
	Wed, 22 Feb 2006 01:04:22 GMT
	(envelope-from nobody)
Message-Id: <200602220104.k1M14MZi063744@www.freebsd.org>
Date: Wed, 22 Feb 2006 01:04:22 GMT
From: Ian West <ian@niw.com.au>
To: freebsd-gnats-submit@FreeBSD.org
Subject: select on pipe write fails from '0' end
X-Send-Pr-Version: www-2.3

>Number:         93685
>Category:       kern
>Synopsis:       [pipe] select on pipe write fails from '0' end
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 22 01:10:03 GMT 2006
>Closed-Date:    Fri Mar 15 23:29:47 UTC 2013
>Last-Modified:  Fri Mar 15 23:29:47 UTC 2013
>Originator:     Ian West
>Release:        6.1pre
>Organization:
>Environment:
FreeBSD 6.1-PRERELEASE Sun Feb 5
>Description:
I have an application which has always opened a pipe and used the 0 index as the writer and the 1 index as the reader when forking. Admittedly this is against the recommendation, but with previous versions of BSD it has been fine (up to 4.11). With this code migrated to 6.1PRE, the select for write never returns true. If I swap the fd's around the problem is resolved. Easy for me to sort out, but could be a problem for bidirectional pipe users ?         
>How-To-Repeat:
Configure a pipe the 'wrong' way around. Write to fd[0] on the source end, try and configure this for non-blocking using select on write buffer available. Using fd[1] from the pipe command works correctly. 4.11 works either way.
>Fix:

>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, ian@niw.com.au
Cc:  
Subject: Re: kern/93685: [pipe] select on pipe write fails from '0' end
Date: Sat, 15 May 2010 22:54:36 +0200

 Confirmed on 8.0-STABLE and 9-CURRENT. I think it has to do with the
 lazy initialization of the "secondary" direction: if I write a byte in
 that direction first, the select behaves correctly.
 
 -- 
 Jilles Tjoelker
State-Changed-From-To: open->analyzed 
State-Changed-By: linimon 
State-Changed-When: Wed Aug 4 03:42:27 UTC 2010 
State-Changed-Why:  
Confirmed to still be a problem by jilles. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=93685 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/93685: commit references a PR
Date: Wed, 14 Dec 2011 22:26:53 +0000 (UTC)

 Author: jilles
 Date: Wed Dec 14 22:26:39 2011
 New Revision: 228510
 URL: http://svn.freebsd.org/changeset/base/228510
 
 Log:
   Fix select/poll/kqueue for write on reverse direction before first write.
   
   The reverse direction of a pipe is lazily allocated on the first write in
   that direction (because pipes are usually used in one direction only).  A
   special case is needed to ensure the pipe appears writable before the first
   write because there are 0 bytes of pending data in 0 bytes of buffer space
   at that point, leaving 0 bytes of data that can be written with the normal
   code.
   
   Note that the first write returns [ENOMEM] if kern.ipc.maxpipekva is
   exceeded and does not block or return [EAGAIN], so selecting true for write
   is correct even in that case.
   
   PR:		kern/93685
   Submitted by:	gianni
   MFC after:	2 weeks
 
 Modified:
   head/sys/kern/sys_pipe.c
 
 Modified: head/sys/kern/sys_pipe.c
 ==============================================================================
 --- head/sys/kern/sys_pipe.c	Wed Dec 14 22:22:19 2011	(r228509)
 +++ head/sys/kern/sys_pipe.c	Wed Dec 14 22:26:39 2011	(r228510)
 @@ -1349,7 +1349,8 @@ pipe_poll(fp, events, active_cred, td)
  		if (wpipe->pipe_present != PIPE_ACTIVE ||
  		    (wpipe->pipe_state & PIPE_EOF) ||
  		    (((wpipe->pipe_state & PIPE_DIRECTW) == 0) &&
 -		     (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF))
 +		     ((wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF ||
 +			 wpipe->pipe_buffer.size == 0)))
  			revents |= events & (POLLOUT | POLLWRNORM);
  
  	if ((events & POLLINIGNEOF) == 0) {
 @@ -1660,7 +1661,8 @@ filt_pipewrite(struct knote *kn, long hi
  		PIPE_UNLOCK(rpipe);
  		return (1);
  	}
 -	kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
 +	kn->kn_data = (wpipe->pipe_buffer.size > 0) ?
 +	    (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) : PIPE_BUF;
  	if (wpipe->pipe_state & PIPE_DIRECTW)
  		kn->kn_data = 0;
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: jilles 
State-Changed-When: Wed Dec 14 22:50:38 UTC 2011 
State-Changed-Why:  
Fixed in 10-current. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Wed Dec 14 22:50:38 UTC 2011 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=93685 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/93685: commit references a PR
Date: Fri,  3 Feb 2012 20:24:29 +0000 (UTC)

 Author: jilles
 Date: Fri Feb  3 20:24:18 2012
 New Revision: 230955
 URL: http://svn.freebsd.org/changeset/base/230955
 
 Log:
   MFC r228510: Fix select/poll/kqueue for write on reverse direction before
   first write.
   
   The reverse direction of a pipe is lazily allocated on the first write in
   that direction (because pipes are usually used in one direction only).  A
   special case is needed to ensure the pipe appears writable before the first
   write because there are 0 bytes of pending data in 0 bytes of buffer space
   at that point, leaving 0 bytes of data that can be written with the normal
   code.
   
   Note that the first write returns [ENOMEM] if kern.ipc.maxpipekva is
   exceeded and does not block or return [EAGAIN], so selecting true for write
   is correct even in that case.
   
   PR:		kern/93685
 
 Modified:
   stable/9/sys/kern/sys_pipe.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/kern/sys_pipe.c
 ==============================================================================
 --- stable/9/sys/kern/sys_pipe.c	Fri Feb  3 20:20:30 2012	(r230954)
 +++ stable/9/sys/kern/sys_pipe.c	Fri Feb  3 20:24:18 2012	(r230955)
 @@ -1349,7 +1349,8 @@ pipe_poll(fp, events, active_cred, td)
  		if (wpipe->pipe_present != PIPE_ACTIVE ||
  		    (wpipe->pipe_state & PIPE_EOF) ||
  		    (((wpipe->pipe_state & PIPE_DIRECTW) == 0) &&
 -		     (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF))
 +		     ((wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF ||
 +			 wpipe->pipe_buffer.size == 0)))
  			revents |= events & (POLLOUT | POLLWRNORM);
  
  	if ((events & POLLINIGNEOF) == 0) {
 @@ -1660,7 +1661,8 @@ filt_pipewrite(struct knote *kn, long hi
  		PIPE_UNLOCK(rpipe);
  		return (1);
  	}
 -	kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
 +	kn->kn_data = (wpipe->pipe_buffer.size > 0) ?
 +	    (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) : PIPE_BUF;
  	if (wpipe->pipe_state & PIPE_DIRECTW)
  		kn->kn_data = 0;
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 15 23:29:45 UTC 2013 
State-Changed-Why:  
MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=93685 
>Unformatted:
