On Wed, 05 Feb 2020 at 17:48:41 -0700, Todd C. Miller wrote:
> On Wed, 05 Feb 2020 15:47:37 -0600, joshua stein wrote:
>
> > The spec says the behavior of anything other than O_RDWR and
> > O_NOCTTY is unspecified, but FreeBSD allows passing O_CLOEXEC.
>
> OK, but the manual needs to specify that O_CLOEXEC support is an
> extension. E.g., under STANDARDS:
>
> The ability to use
> .Dv O_CLOEXEC
> is an extension to that standard.
Thanks, incorporated.
Index: lib/libc/stdlib/posix_openpt.3
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/posix_openpt.3,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 posix_openpt.3
--- lib/libc/stdlib/posix_openpt.3 25 Jan 2019 00:19:25 -0000 1.4
+++ lib/libc/stdlib/posix_openpt.3 6 Feb 2020 16:01:58 -0000
@@ -45,7 +45,7 @@ argument is formed by bitwise-inclusive
.Tn OR Ns 'ing
the following values defined in
.In fcntl.h :
-.Bl -tag -width O_NOCTTY -offset indent
+.Bl -tag -width O_CLOEXEC -offset indent
.It Dv O_RDWR
Open for reading and writing.
.It Dv O_NOCTTY
@@ -53,6 +53,8 @@ Prevent the device from being made the c
This flag has no effect on
.Ox
and is included for compatibility with other systems.
+.It Dv O_CLOEXEC
+Set the close-on-exec flag for the new file descriptor.
.El
.Pp
The
@@ -95,6 +97,10 @@ The
.Fn posix_openpt
function conforms to
.St -p1003.1-2001 .
+.Pp
+The ability to use
+.Dv O_CLOEXEC
+is an extension to that standard.
.Sh HISTORY
The
.Fn posix_openpt
Index: lib/libc/stdlib/posix_pty.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/posix_pty.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 posix_pty.c
--- lib/libc/stdlib/posix_pty.c 25 Jan 2019 00:19:25 -0000 1.3
+++ lib/libc/stdlib/posix_pty.c 6 Feb 2020 16:01:58 -0000
@@ -36,13 +36,13 @@ posix_openpt(int oflag)
/* User must specify O_RDWR in oflag. */
if ((oflag & O_ACCMODE) != O_RDWR ||
- (oflag & ~(O_ACCMODE | O_NOCTTY)) != 0) {
+ (oflag & ~(O_ACCMODE | O_NOCTTY | O_CLOEXEC)) != 0) {
errno = EINVAL;
return -1;
}
/* Get pty master and slave (this API only uses the master). */
- fd = open(PATH_PTMDEV, O_RDWR);
+ fd = open(PATH_PTMDEV, oflag);
if (fd != -1) {
if (ioctl(fd, PTMGET, &ptm) != -1) {
close(ptm.sfd);