Seems very reasonable.

joshua stein <j...@openbsd.org> wrote:

> The spec says the behavior of anything other than O_RDWR and 
> O_NOCTTY is unspecified, but FreeBSD allows passing O_CLOEXEC.
> 
> 
> 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    5 Feb 2020 21:41:00 -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
> 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       5 Feb 2020 21:41:00 -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);
> 

Reply via email to