From d0e18f58af39d455a40c4a1408f98279f45caef3 Mon Sep 17 00:00:00 2001 From: Visa Hankala Date: Wed, 8 Jan 2020 16:27:43 +0000 Subject: 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@ --- sys/kern/tty.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sys/kern/tty.c') 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); -- cgit v1.2.3