summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authorvisa <visa@openbsd.org>2020-01-08 16:27:40 +0000
committervisa <visa@openbsd.org>2020-01-08 16:27:40 +0000
commit36b1b8b4dfaf3411193c17c2462937014292f2df (patch)
tree81f30bc60ac32c23151dd9b7753c67c177381297 /sys/kern/tty.c
parentConvert infinite sleeps to tsleep_nsec(9). (diff)
downloadwireguard-openbsd-36b1b8b4dfaf3411193c17c2462937014292f2df.tar.xz
wireguard-openbsd-36b1b8b4dfaf3411193c17c2462937014292f2df.zip
Unify handling of ioctls FIOSETOWN/SIOCSPGRP/TIOCSPGRP and
FIOGETOWN/SIOCGPGRP/TIOCGPGRP. Do this by determining the meaning of the ID parameter inside the sigio code. Also add cases for FIOSETOWN and FIOGETOWN where there have been TIOCSPGRP and TIOCGPGRP before. These changes allow removing the ID translation from sys_fcntl() and sys_ioctl(). Idea from NetBSD OK mpi@, claudio@
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index d73714f77d8..5ada4fd2b6c 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.149 2019/12/31 13:48:32 visa Exp $ */
+/* $OpenBSD: tty.c,v 1.150 2020/01/08 16:27:41 visa Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -723,6 +723,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
/* If the ioctl involves modification, hang if in the background. */
switch (cmd) {
+ case FIOSETOWN:
case TIOCFLUSH:
case TIOCDRAIN:
case TIOCSBRK:
@@ -829,6 +830,11 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
*(struct timeval *)data = tp->t_tv;
splx(s);
break;
+ case FIOGETOWN: /* get pgrp of tty */
+ if (!isctty(pr, tp) && suser(p))
+ return (ENOTTY);
+ *(int *)data = tp->t_pgrp ? -tp->t_pgrp->pg_id : 0;
+ break;
case TIOCGPGRP: /* get pgrp of tty */
if (!isctty(pr, tp) && suser(p))
return (ENOTTY);
@@ -983,6 +989,28 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
pr->ps_session->s_ttyp = tp;
atomic_setbits_int(&pr->ps_flags, PS_CONTROLT);
break;
+ case FIOSETOWN: { /* set pgrp of tty */
+ struct pgrp *pgrp;
+ struct process *pr1;
+ pid_t pgid = *(int *)data;
+
+ if (!isctty(pr, tp))
+ return (ENOTTY);
+ if (pgid < 0) {
+ pgrp = pgfind(-pgid);
+ } else {
+ pr1 = prfind(pgid);
+ if (pr1 == NULL)
+ return (ESRCH);
+ pgrp = pr1->ps_pgrp;
+ }
+ if (pgrp == NULL)
+ return (EINVAL);
+ else if (pgrp->pg_session != pr->ps_session)
+ return (EPERM);
+ tp->t_pgrp = pgrp;
+ break;
+ }
case TIOCSPGRP: { /* set pgrp of tty */
struct pgrp *pgrp = pgfind(*(int *)data);