tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Open master pty (/dev/ptmx) non blocking
On Fri, 23 Sep 2022, David Holland wrote:
> While my inclination would be to make it work, until someone wants to
> figure out how to do that it seems straightforward to make O_NONBLOCK
> fail:
Mostly out of curiosity and for the records, I tested the attached
patch. It enables the EINVAL error for unsupported flags and sets
O_NONBLOCK if present. This seems to work after a quick test.
Regarding the O_CLOEXEC, it may require a bit more work. I feel like
the fd_set_exclose() function in kern_descrip.c could be used.
Index: sys/kern/tty_ptm.c
===================================================================
RCS file: /cvsroot/src/sys/kern/tty_ptm.c,v
retrieving revision 1.43
diff -u -r1.43 tty_ptm.c
--- sys/kern/tty_ptm.c 29 Jun 2021 22:40:53 -0000 1.43
+++ sys/kern/tty_ptm.c 24 Sep 2022 15:41:44 -0000
@@ -87,7 +87,7 @@
int pts_major, ptc_major;
static dev_t pty_getfree(void);
-static int pty_alloc_master(struct lwp *, int *, dev_t *, struct mount *);
+static int pty_alloc_master(struct lwp *, int, int *, dev_t *, struct mount *);
static int pty_alloc_slave(struct lwp *, int *, dev_t, struct mount *);
static int pty_vn_open(struct vnode *, struct lwp *);
@@ -155,13 +155,16 @@
}
static int
-pty_alloc_master(struct lwp *l, int *fd, dev_t *dev, struct mount *mp)
+pty_alloc_master(struct lwp *l, int flag, int *fd, dev_t *dev, struct mount *mp)
{
int error;
struct file *fp;
struct vnode *vp;
int md;
+ if (flag & ~(O_ACCMODE | O_NOCTTY | O_NONBLOCK))
+ return EINVAL;
+
if ((error = fd_allocfile(&fp, fd)) != 0) {
DPRINTF(("fd_allocfile %d\n", error));
return error;
@@ -199,7 +202,7 @@
else
goto bad;
}
- fp->f_flag = FREAD|FWRITE;
+ fp->f_flag = FREAD|FWRITE | (flag & O_NONBLOCK);
fp->f_type = DTYPE_VNODE;
fp->f_ops = &vnops;
fp->f_vnode = vp;
@@ -343,7 +346,7 @@
case 2: /* /emul/linux/dev/ptmx */
if ((error = pty_getmp(l, &mp)) != 0)
return error;
- if ((error = pty_alloc_master(l, &fd, &ttydev, mp)) != 0)
+ if ((error = pty_alloc_master(l, flag, &fd, &ttydev, mp)) != 0)
return error;
if (minor(dev) == 2) {
/*
@@ -392,7 +395,7 @@
if ((error = pty_getmp(l, &mp)) != 0)
return error;
- if ((error = pty_alloc_master(l, &cfd, &newdev, mp)) != 0)
+ if ((error = pty_alloc_master(l, 0, &cfd, &newdev, mp)) != 0)
return error;
if ((error = pty_grant_slave(l, newdev, mp)) != 0)
Home |
Main Index |
Thread Index |
Old Index