summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authorvisa <visa@openbsd.org>2020-02-08 14:52:07 +0000
committervisa <visa@openbsd.org>2020-02-08 14:52:07 +0000
commita816bf094c34eb05a7d35a1d6119cf6d2088074c (patch)
tree85bafcf68af4280c4b1ea7b25b9d6bac8cfd25bb /sys/kern/tty.c
parentremove erroneous line in comment for vm_get_info() (diff)
downloadwireguard-openbsd-a816bf094c34eb05a7d35a1d6119cf6d2088074c.tar.xz
wireguard-openbsd-a816bf094c34eb05a7d35a1d6119cf6d2088074c.zip
Replace ttkqflush() with klist_invalidate() to handle knote list
invalidation in one place. Store struct tty pointer in kn_hook directly to simplify the code. OK mpi@
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c57
1 files changed, 11 insertions, 46 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index ffc4d120e84..2e02e126dc8 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.151 2020/01/09 14:35:20 mpi Exp $ */
+/* $OpenBSD: tty.c,v 1.152 2020/02/08 14:52:07 visa Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -75,7 +75,6 @@ static void ttyblock(struct tty *);
void ttyunblock(struct tty *);
static void ttyecho(int, struct tty *);
static void ttyrubo(struct tty *, int);
-void ttkqflush(struct klist *klist);
int filt_ttyread(struct knote *kn, long hint);
void filt_ttyrdetach(struct knote *kn);
int filt_ttywrite(struct knote *kn, long hint);
@@ -1124,7 +1123,7 @@ ttkqfilter(dev_t dev, struct knote *kn)
return (EINVAL);
}
- kn->kn_hook = (caddr_t)((u_long)dev);
+ kn->kn_hook = tp;
s = spltty();
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
@@ -1134,29 +1133,11 @@ ttkqfilter(dev_t dev, struct knote *kn)
}
void
-ttkqflush(struct klist *klist)
-{
- struct knote *kn, *kn1;
-
- SLIST_FOREACH_SAFE(kn, klist, kn_selnext, kn1) {
- SLIST_REMOVE(klist, kn, knote, kn_selnext);
- kn->kn_hook = (caddr_t)((u_long)NODEV);
- kn->kn_flags |= EV_EOF;
- knote_activate(kn);
- }
-}
-
-void
filt_ttyrdetach(struct knote *kn)
{
- dev_t dev = (dev_t)((u_long)kn->kn_hook);
- struct tty *tp;
+ struct tty *tp = kn->kn_hook;
int s;
- if (dev == NODEV)
- return;
- tp = (*cdevsw[major(dev)].d_tty)(dev);
-
s = spltty();
SLIST_REMOVE(&tp->t_rsel.si_note, kn, knote, kn_selnext);
splx(s);
@@ -1165,16 +1146,9 @@ filt_ttyrdetach(struct knote *kn)
int
filt_ttyread(struct knote *kn, long hint)
{
- dev_t dev = (dev_t)((u_long)kn->kn_hook);
- struct tty *tp;
+ struct tty *tp = kn->kn_hook;
int s;
- if (dev == NODEV) {
- kn->kn_flags |= EV_EOF;
- return (1);
- }
- tp = (*cdevsw[major(dev)].d_tty)(dev);
-
s = spltty();
kn->kn_data = ttnread(tp);
splx(s);
@@ -1188,14 +1162,9 @@ filt_ttyread(struct knote *kn, long hint)
void
filt_ttywdetach(struct knote *kn)
{
- dev_t dev = (dev_t)((u_long)kn->kn_hook);
- struct tty *tp;
+ struct tty *tp = kn->kn_hook;
int s;
- if (dev == NODEV)
- return;
- tp = (*cdevsw[major(dev)].d_tty)(dev);
-
s = spltty();
SLIST_REMOVE(&tp->t_wsel.si_note, kn, knote, kn_selnext);
splx(s);
@@ -1204,16 +1173,9 @@ filt_ttywdetach(struct knote *kn)
int
filt_ttywrite(struct knote *kn, long hint)
{
- dev_t dev = (dev_t)((u_long)kn->kn_hook);
- struct tty *tp;
+ struct tty *tp = kn->kn_hook;
int canwrite, s;
- if (dev == NODEV) {
- kn->kn_flags |= EV_EOF;
- return (1);
- }
- tp = (*cdevsw[major(dev)].d_tty)(dev);
-
s = spltty();
kn->kn_data = tp->t_outq.c_cn - tp->t_outq.c_cc;
canwrite = (tp->t_outq.c_cc <= tp->t_lowat);
@@ -2378,6 +2340,7 @@ ttymalloc(int baud)
void
ttyfree(struct tty *tp)
{
+ int s;
--tty_count;
#ifdef DIAGNOSTIC
@@ -2386,8 +2349,10 @@ ttyfree(struct tty *tp)
#endif
TAILQ_REMOVE(&ttylist, tp, tty_link);
- ttkqflush(&tp->t_rsel.si_note);
- ttkqflush(&tp->t_wsel.si_note);
+ s = spltty();
+ klist_invalidate(&tp->t_rsel.si_note);
+ klist_invalidate(&tp->t_wsel.si_note);
+ splx(s);
clfree(&tp->t_rawq);
clfree(&tp->t_canq);