kern/162374: posix_openpt wrongly removed O_CLOEXEC

Jilles Tjoelker jilles at
Wed Mar 20 23:50:02 UTC 2013

The following reply was made to PR kern/162374; it has been noted by GNATS.

From: Jilles Tjoelker <jilles at>
To: bug-followup at, naruse at, ed at
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, 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
 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.
 @@ -79,6 +79,8 @@
  .Fn posix_openpt
  shall not cause the terminal device to become the controlling terminal
  for the process.
 +Set the close-on-exec flag for the new file descriptor.
 Jilles Tjoelker

More information about the freebsd-bugs mailing list