From owner-freebsd-bugs@FreeBSD.ORG Wed Mar 20 23:50:02 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3E165AAC for ; Wed, 20 Mar 2013 23:50:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 16660B2C for ; Wed, 20 Mar 2013 23:50:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r2KNo1oC018735 for ; Wed, 20 Mar 2013 23:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r2KNo1PH018734; Wed, 20 Mar 2013 23:50:01 GMT (envelope-from gnats) Date: Wed, 20 Mar 2013 23:50:01 GMT Message-Id: <201303202350.r2KNo1PH018734@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: kern/162374: posix_openpt wrongly removed O_CLOEXEC X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Mar 2013 23:50:02 -0000 The following reply was made to PR kern/162374; it has been noted by GNATS. From: Jilles Tjoelker 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