diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2020-01-08 16:27:43 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2020-01-08 16:27:43 +0000 |
commit | d0e18f58af39d455a40c4a1408f98279f45caef3 (patch) | |
tree | b707f917d62851a404877009a45c6e59fc24a47f /sys/kern/tty.c | |
parent | 2446fb56753f948228e61f6de87c7b869153c29b (diff) |
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.c | 30 |
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); |