Skip to content

Commit 81cd091

Browse files
Pull up following revision(s) (requested by gutteridge in ticket #8):
tests/lib/libc/ttyio/t_ptm.c: revision 1.3 lib/libc/stdlib/posix_openpt.3: revision 1.11 sys/kern/tty_ptm.c: revision 1.47 tty_ptm.c: support setting O_CLOFORK here as well t_ptm.c: now also validate O_CLOFORK can be set posix_openpt.3: note O_CLOFORK is also now supported
1 parent 9751681 commit 81cd091

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

lib/libc/stdlib/posix_openpt.3

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" $NetBSD: posix_openpt.3,v 1.10 2022/11/15 22:17:53 gutteridge Exp $
1+
.\" $NetBSD: posix_openpt.3,v 1.10.6.1 2025/08/08 16:37:02 martin Exp $
22
.\"
33
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
44
.\" All rights reserved.
@@ -27,7 +27,7 @@
2727
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2828
.\" POSSIBILITY OF SUCH DAMAGE.
2929
.\"
30-
.Dd November 15, 2022
30+
.Dd August 6, 2025
3131
.Dt POSIX_OPENPT 3
3232
.Os
3333
.Sh NAME
@@ -73,9 +73,10 @@ flags are possible to set, and apply a fallback if
7373
.Er EINVAL
7474
is received.
7575
However, this is unlikely to be a concern in practice, as flags such as
76-
.Dv O_NONBLOCK
76+
.Dv O_NONBLOCK ,
77+
.Dv O_CLOEXEC ,
7778
and
78-
.Dv O_CLOEXEC
79+
.Dv O_CLOFORK
7980
are supported.
8081
.Sh SEE ALSO
8182
.Xr ioctl 2 ,

sys/kern/tty_ptm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: tty_ptm.c,v 1.46 2023/04/09 09:18:09 riastradh Exp $ */
1+
/* $NetBSD: tty_ptm.c,v 1.46.8.1 2025/08/08 16:37:02 martin Exp $ */
22

33
/*-
44
* Copyright (c) 2004, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <sys/cdefs.h>
30-
__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.46 2023/04/09 09:18:09 riastradh Exp $");
30+
__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.46.8.1 2025/08/08 16:37:02 martin Exp $");
3131

3232
#ifdef _KERNEL_OPT
3333
#include "opt_compat_netbsd.h"
@@ -208,6 +208,7 @@ pty_alloc_master(struct lwp *l, int *fd, dev_t *dev, struct mount *mp,
208208

209209
VOP_UNLOCK(vp);
210210
fd_set_exclose(l, *fd, (flags & O_CLOEXEC) != 0);
211+
fd_set_foclose(l, *fd, (flags & O_CLOFORK) != 0);
211212
fd_affix(curproc, fp, *fd);
212213
return 0;
213214
bad:

tests/lib/libc/ttyio/t_ptm.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: t_ptm.c,v 1.2 2023/05/17 03:16:11 gutteridge Exp $ */
1+
/* $NetBSD: t_ptm.c,v 1.2.4.1 2025/08/08 16:37:02 martin Exp $ */
22

33
/*
44
* Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
3232
#include <sys/cdefs.h>
3333
__COPYRIGHT("@(#) Copyright (c) 2008\
3434
The NetBSD Foundation, inc. All rights reserved.");
35-
__RCSID("$NetBSD: t_ptm.c,v 1.2 2023/05/17 03:16:11 gutteridge Exp $");
35+
__RCSID("$NetBSD: t_ptm.c,v 1.2.4.1 2025/08/08 16:37:02 martin Exp $");
3636

3737
#include <sys/ioctl.h>
3838
#include <sys/stat.h>
@@ -170,23 +170,22 @@ ATF_TC_HEAD(ptmx_extra, tc)
170170
{
171171

172172
atf_tc_set_md_var(tc, "descr", "Checks /dev/ptmx device "
173-
"applies O_NONBLOCK and O_CLOEXEC");
173+
"applies O_NONBLOCK, O_CLOEXEC, and O_CLOFORK");
174174
}
175175

176176
ATF_TC_BODY(ptmx_extra, tc)
177177
{
178178
int fdm;
179179

180-
if ((fdm = posix_openpt(O_RDWR|O_NOCTTY|O_NONBLOCK|O_CLOEXEC)) == -1) {
180+
if ((fdm = posix_openpt(O_RDWR|O_NONBLOCK|O_CLOEXEC|O_CLOFORK)) == -1) {
181181
if (errno == ENOENT || errno == ENODEV)
182182
atf_tc_skip("/dev/ptmx: %s", strerror(errno));
183183

184184
atf_tc_fail("/dev/ptmx: %s", strerror(errno));
185185
}
186186

187-
/* O_NOCTTY is ignored, not set. */
188187
ATF_CHECK_EQ(O_RDWR|O_NONBLOCK, fcntl(fdm, F_GETFL));
189-
ATF_CHECK_EQ(FD_CLOEXEC, fcntl(fdm, F_GETFD));
188+
ATF_CHECK_EQ(FD_CLOEXEC|FD_CLOFORK, fcntl(fdm, F_GETFD));
190189
}
191190

192191
ATF_TP_ADD_TCS(tp)

0 commit comments

Comments
 (0)