From nobody@FreeBSD.org  Tue Nov  8 08:42:57 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 9A4A31065670
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  8 Nov 2011 08:42:57 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 8B1D68FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  8 Nov 2011 08:42:57 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pA88gulg015679
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 8 Nov 2011 08:42:56 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pA88guL0015678;
	Tue, 8 Nov 2011 08:42:56 GMT
	(envelope-from nobody)
Message-Id: <201111080842.pA88guL0015678@red.freebsd.org>
Date: Tue, 8 Nov 2011 08:42:56 GMT
From: Yui NARUSE <naruse@airemix.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: posix_openpt wrongly removed O_CLOEXEC
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         162374
>Category:       kern
>Synopsis:       posix_openpt wrongly removed O_CLOEXEC
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 08 08:50:00 UTC 2011
>Closed-Date:    Fri May 24 19:05:12 UTC 2013
>Last-Modified:  Fri May 24 19:05:12 UTC 2013
>Originator:     Yui NARUSE
>Release:        FreeBSD 9.0-RC1
>Organization:
>Environment:
FreeBSD windy.airemix.net 9.0-RC1 FreeBSD 9.0-RC1 #0: Tue Oct 18 18:51:43 UTC 2011     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
FreeBSD 8 undocumentedly supported O_CLOEXEC flag for posix_openpt.
But FreeBSD 9 removed it because it is not in SuSv4.
http://freebsd.1045724.n5.nabble.com/O-CLOEXEC-td4263370.html

However next SuS will add O_CLOEXEC for posix_openpt just as FreeBSD 8.2 did.
http://austingroupbugs.net/view.php?id=411

This means, FreeBSD 8.2 and future FreeBSD supports O_CLOEXEC for posix_openpt, but FreeBSD 9.0 doesn't. It is very confusing.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, naruse@airemix.jp, ed@FreeBSD.org
Cc:  
Subject: Re: kern/162374: posix_openpt wrongly removed O_CLOEXEC
Date: Thu, 21 Mar 2013 00:42:48 +0100

 PR kern/162374:
 > [posix_openpt(O_RDWR | O_NOCTTY | O_CLOEXEC) fails with [EINVAL]]
 
 While looking at all the atomic close-on-exec changes in
 http://austingroupbugs.net/view.php?id=411, I found this PR. It seems to
 make sense to allow O_CLOEXEC in posix_openpt(), so that this way of
 creating a new file descriptor can also create it atomically
 close-on-exec.
 
 The O_CLOEXEC flag does not seem to have been "removed" as it was never
 present in the first place (even stable/7's userland implementation
 gives [EINVAL] for anything but O_RDWR and O_NOCTTY).
 
 Ed, what do you think of this patch?
 
 Index: sys/kern/tty_pts.c
 ===================================================================
 --- sys/kern/tty_pts.c	(revision 248561)
 +++ sys/kern/tty_pts.c	(working copy)
 @@ -825,10 +825,10 @@
  	 * POSIX states it's unspecified when other flags are passed. We
  	 * don't allow this.
  	 */
 -	if (uap->flags & ~(O_RDWR|O_NOCTTY))
 +	if (uap->flags & ~(O_RDWR|O_NOCTTY|O_CLOEXEC))
  		return (EINVAL);
  
 -	error = falloc(td, &fp, &fd, 0);
 +	error = falloc(td, &fp, &fd, uap->flags);
  	if (error)
  		return (error);
  
 Index: lib/libc/sys/posix_openpt.2
 ===================================================================
 --- lib/libc/sys/posix_openpt.2	(revision 248561)
 +++ lib/libc/sys/posix_openpt.2	(working copy)
 @@ -71,7 +71,7 @@
  are constructed by a bitwise-inclusive OR of flags from the following
  list, defined in
  .In fcntl.h :
 -.Bl -tag -width ".Dv O_NOCTTY"
 +.Bl -tag -width ".Dv O_CLOEXEC"
  .It Dv O_RDWR
  Open for reading and writing.
  .It Dv O_NOCTTY
 @@ -79,6 +79,8 @@
  .Fn posix_openpt
  shall not cause the terminal device to become the controlling terminal
  for the process.
 +.It Dv O_CLOEXEC
 +Set the close-on-exec flag for the new file descriptor.
  .El
  .Pp
  The
 
 -- 
 Jilles Tjoelker

From: Ed Schouten <ed@80386.nl>
To: Jilles Tjoelker <jilles@stack.nl>
Cc: bug-followup@freebsd.org, naruse@airemix.jp
Subject: Re: kern/162374: posix_openpt wrongly removed O_CLOEXEC
Date: Thu, 21 Mar 2013 03:58:28 +0100

 2013/3/21 Jilles Tjoelker <jilles@stack.nl>:
 > Ed, what do you think of this patch?
 
 Looks good!
 
 -- 
 Ed Schouten <ed@80386.nl>

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/162374: commit references a PR
Date: Thu, 21 Mar 2013 21:39:28 +0000 (UTC)

 Author: jilles
 Date: Thu Mar 21 21:39:15 2013
 New Revision: 248593
 URL: http://svnweb.freebsd.org/changeset/base/248593
 
 Log:
   Allow O_CLOEXEC in posix_openpt() flags.
   
   PR:		kern/162374
   Reviewed by:	ed
 
 Modified:
   head/lib/libc/sys/posix_openpt.2
   head/sys/kern/tty_pts.c
 
 Modified: head/lib/libc/sys/posix_openpt.2
 ==============================================================================
 --- head/lib/libc/sys/posix_openpt.2	Thu Mar 21 20:14:51 2013	(r248592)
 +++ head/lib/libc/sys/posix_openpt.2	Thu Mar 21 21:39:15 2013	(r248593)
 @@ -37,7 +37,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd August 20, 2008
 +.Dd March 21, 2013
  .Dt POSIX_OPENPT 2
  .Os
  .Sh NAME
 @@ -71,7 +71,7 @@ Values for
  are constructed by a bitwise-inclusive OR of flags from the following
  list, defined in
  .In fcntl.h :
 -.Bl -tag -width ".Dv O_NOCTTY"
 +.Bl -tag -width ".Dv O_CLOEXEC"
  .It Dv O_RDWR
  Open for reading and writing.
  .It Dv O_NOCTTY
 @@ -79,6 +79,8 @@ If set
  .Fn posix_openpt
  shall not cause the terminal device to become the controlling terminal
  for the process.
 +.It Dv O_CLOEXEC
 +Set the close-on-exec flag for the new file descriptor.
  .El
  .Pp
  The
 @@ -116,6 +118,9 @@ The
  .Fn posix_openpt
  function conforms to
  .St -p1003.1-2001 .
 +The ability to use
 +.Dv O_CLOEXEC
 +is an extension to the standard.
  .Sh HISTORY
  The
  .Fn posix_openpt
 
 Modified: head/sys/kern/tty_pts.c
 ==============================================================================
 --- head/sys/kern/tty_pts.c	Thu Mar 21 20:14:51 2013	(r248592)
 +++ head/sys/kern/tty_pts.c	Thu Mar 21 21:39:15 2013	(r248593)
 @@ -825,10 +825,10 @@ sys_posix_openpt(struct thread *td, stru
  	 * POSIX states it's unspecified when other flags are passed. We
  	 * don't allow this.
  	 */
 -	if (uap->flags & ~(O_RDWR|O_NOCTTY))
 +	if (uap->flags & ~(O_RDWR|O_NOCTTY|O_CLOEXEC))
  		return (EINVAL);
  
 -	error = falloc(td, &fp, &fd, 0);
 +	error = falloc(td, &fp, &fd, uap->flags);
  	if (error)
  		return (error);
  
 _______________________________________________
 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: open->patched 
State-Changed-By: jilles 
State-Changed-When: Thu Mar 21 22:26:44 UTC 2013 
State-Changed-Why:  
Fixed in 10-current. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Thu Mar 21 22:26:44 UTC 2013 
Responsible-Changed-Why:  
I did the commit. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/162374: commit references a PR
Date: Fri, 24 May 2013 18:59:52 +0000 (UTC)

 Author: jilles
 Date: Fri May 24 18:59:44 2013
 New Revision: 250973
 URL: http://svnweb.freebsd.org/changeset/base/250973
 
 Log:
   MFC r248593: Allow O_CLOEXEC in posix_openpt() flags.
   
   PR:		kern/162374
 
 Modified:
   stable/9/lib/libc/sys/posix_openpt.2
   stable/9/sys/kern/tty_pts.c
 Directory Properties:
   stable/9/lib/libc/   (props changed)
   stable/9/lib/libc/sys/   (props changed)
   stable/9/sys/   (props changed)
 
 Modified: stable/9/lib/libc/sys/posix_openpt.2
 ==============================================================================
 --- stable/9/lib/libc/sys/posix_openpt.2	Fri May 24 18:54:52 2013	(r250972)
 +++ stable/9/lib/libc/sys/posix_openpt.2	Fri May 24 18:59:44 2013	(r250973)
 @@ -37,7 +37,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd August 20, 2008
 +.Dd March 21, 2013
  .Dt POSIX_OPENPT 2
  .Os
  .Sh NAME
 @@ -71,7 +71,7 @@ Values for
  are constructed by a bitwise-inclusive OR of flags from the following
  list, defined in
  .In fcntl.h :
 -.Bl -tag -width ".Dv O_NOCTTY"
 +.Bl -tag -width ".Dv O_CLOEXEC"
  .It Dv O_RDWR
  Open for reading and writing.
  .It Dv O_NOCTTY
 @@ -79,6 +79,8 @@ If set
  .Fn posix_openpt
  shall not cause the terminal device to become the controlling terminal
  for the process.
 +.It Dv O_CLOEXEC
 +Set the close-on-exec flag for the new file descriptor.
  .El
  .Pp
  The
 @@ -116,6 +118,9 @@ The
  .Fn posix_openpt
  function conforms to
  .St -p1003.1-2001 .
 +The ability to use
 +.Dv O_CLOEXEC
 +is an extension to the standard.
  .Sh HISTORY
  The
  .Fn posix_openpt
 
 Modified: stable/9/sys/kern/tty_pts.c
 ==============================================================================
 --- stable/9/sys/kern/tty_pts.c	Fri May 24 18:54:52 2013	(r250972)
 +++ stable/9/sys/kern/tty_pts.c	Fri May 24 18:59:44 2013	(r250973)
 @@ -825,10 +825,10 @@ sys_posix_openpt(struct thread *td, stru
  	 * POSIX states it's unspecified when other flags are passed. We
  	 * don't allow this.
  	 */
 -	if (uap->flags & ~(O_RDWR|O_NOCTTY))
 +	if (uap->flags & ~(O_RDWR|O_NOCTTY|O_CLOEXEC))
  		return (EINVAL);
  
 -	error = falloc(td, &fp, &fd, 0);
 +	error = falloc(td, &fp, &fd, uap->flags);
  	if (error)
  		return (error);
  
 _______________________________________________
 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: jilles 
State-Changed-When: Fri May 24 19:05:11 UTC 2013 
State-Changed-Why:  
Fixed in 10-current and 9-stable. 

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