Deleted Added
full compact
tty.c (132226) tty.c (133741)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 57 unchanged lines hidden (view full) ---

66 * o Check for TS_CARR_ON being set while everything is closed and not
67 * waiting for carrier. TS_CARR_ON isn't cleared if nothing is open,
68 * so it would live until the next open even if carrier drops.
69 * o Restore TS_WOPEN since it is useful in pstat. It must be cleared
70 * only when _all_ openers leave open().
71 */
72
73#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 57 unchanged lines hidden (view full) ---

66 * o Check for TS_CARR_ON being set while everything is closed and not
67 * waiting for carrier. TS_CARR_ON isn't cleared if nothing is open,
68 * so it would live until the next open even if carrier drops.
69 * o Restore TS_WOPEN since it is useful in pstat. It must be cleared
70 * only when _all_ openers leave open().
71 */
72
73#include <sys/cdefs.h>
74__FBSDID("$FreeBSD: head/sys/kern/tty.c 132226 2004-07-15 20:47:41Z phk $");
74__FBSDID("$FreeBSD: head/sys/kern/tty.c 133741 2004-08-15 06:24:42Z jmg $");
75
76#include "opt_compat.h"
77#include "opt_tty.h"
78
79#include <sys/param.h>
80#include <sys/systm.h>
81#include <sys/filio.h>
82#include <sys/lock.h>

--- 193 unchanged lines hidden (view full) ---

276 clist_free_cblocks(&tp->t_rawq);
277
278 tp->t_gen++;
279 tp->t_line = TTYDISC;
280 tp->t_hotchar = 0;
281 tp->t_pgrp = NULL;
282 tp->t_session = NULL;
283 tp->t_state = 0;
75
76#include "opt_compat.h"
77#include "opt_tty.h"
78
79#include <sys/param.h>
80#include <sys/systm.h>
81#include <sys/filio.h>
82#include <sys/lock.h>

--- 193 unchanged lines hidden (view full) ---

276 clist_free_cblocks(&tp->t_rawq);
277
278 tp->t_gen++;
279 tp->t_line = TTYDISC;
280 tp->t_hotchar = 0;
281 tp->t_pgrp = NULL;
282 tp->t_session = NULL;
283 tp->t_state = 0;
284 knlist_clear(&tp->t_rsel.si_note, 0);
285 knlist_clear(&tp->t_wsel.si_note, 0);
284 ttyrel(tp);
285 splx(s);
286 return (0);
287}
288
289#define FLUSHQ(q) { \
290 if ((q)->c_cc) \
291 ndflush(q, (q)->c_cc); \

--- 962 unchanged lines hidden (view full) ---

1254 { 1, NULL, filt_ttyrdetach, filt_ttyread };
1255static struct filterops ttywrite_filtops =
1256 { 1, NULL, filt_ttywdetach, filt_ttywrite };
1257
1258int
1259ttykqfilter(struct cdev *dev, struct knote *kn)
1260{
1261 struct tty *tp;
286 ttyrel(tp);
287 splx(s);
288 return (0);
289}
290
291#define FLUSHQ(q) { \
292 if ((q)->c_cc) \
293 ndflush(q, (q)->c_cc); \

--- 962 unchanged lines hidden (view full) ---

1256 { 1, NULL, filt_ttyrdetach, filt_ttyread };
1257static struct filterops ttywrite_filtops =
1258 { 1, NULL, filt_ttywdetach, filt_ttywrite };
1259
1260int
1261ttykqfilter(struct cdev *dev, struct knote *kn)
1262{
1263 struct tty *tp;
1262 struct klist *klist;
1264 struct knlist *klist;
1263 int s;
1264
1265 KASSERT(devsw(dev)->d_flags & D_TTY,
1266 ("ttykqfilter() called on non D_TTY device (%s)", devtoname(dev)));
1267 tp = dev->si_tty;
1268 KASSERT(tp != NULL,
1269 ("ttykqfilter(): no tty pointer on device (%s)", devtoname(dev)));
1270 switch (kn->kn_filter) {
1271 case EVFILT_READ:
1272 klist = &tp->t_rsel.si_note;
1273 kn->kn_fop = &ttyread_filtops;
1274 break;
1275 case EVFILT_WRITE:
1276 klist = &tp->t_wsel.si_note;
1277 kn->kn_fop = &ttywrite_filtops;
1278 break;
1279 default:
1265 int s;
1266
1267 KASSERT(devsw(dev)->d_flags & D_TTY,
1268 ("ttykqfilter() called on non D_TTY device (%s)", devtoname(dev)));
1269 tp = dev->si_tty;
1270 KASSERT(tp != NULL,
1271 ("ttykqfilter(): no tty pointer on device (%s)", devtoname(dev)));
1272 switch (kn->kn_filter) {
1273 case EVFILT_READ:
1274 klist = &tp->t_rsel.si_note;
1275 kn->kn_fop = &ttyread_filtops;
1276 break;
1277 case EVFILT_WRITE:
1278 klist = &tp->t_wsel.si_note;
1279 kn->kn_fop = &ttywrite_filtops;
1280 break;
1281 default:
1280 return (1);
1282 return (EINVAL);
1281 }
1282
1283 kn->kn_hook = (caddr_t)dev;
1284
1285 s = spltty();
1283 }
1284
1285 kn->kn_hook = (caddr_t)dev;
1286
1287 s = spltty();
1286 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
1288 knlist_add(klist, kn, 0);
1287 splx(s);
1288
1289 return (0);
1290}
1291
1292static void
1293filt_ttyrdetach(struct knote *kn)
1294{
1295 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1296 int s = spltty();
1297
1289 splx(s);
1290
1291 return (0);
1292}
1293
1294static void
1295filt_ttyrdetach(struct knote *kn)
1296{
1297 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1298 int s = spltty();
1299
1298 SLIST_REMOVE(&tp->t_rsel.si_note, kn, knote, kn_selnext);
1300 knlist_remove(&tp->t_rsel.si_note, kn, 0);
1299 splx(s);
1300}
1301
1302static int
1303filt_ttyread(struct knote *kn, long hint)
1304{
1305 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1306

--- 6 unchanged lines hidden (view full) ---

1313}
1314
1315static void
1316filt_ttywdetach(struct knote *kn)
1317{
1318 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1319 int s = spltty();
1320
1301 splx(s);
1302}
1303
1304static int
1305filt_ttyread(struct knote *kn, long hint)
1306{
1307 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1308

--- 6 unchanged lines hidden (view full) ---

1315}
1316
1317static void
1318filt_ttywdetach(struct knote *kn)
1319{
1320 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1321 int s = spltty();
1322
1321 SLIST_REMOVE(&tp->t_wsel.si_note, kn, knote, kn_selnext);
1323 knlist_remove(&tp->t_wsel.si_note, kn, 0);
1322 splx(s);
1323}
1324
1325static int
1326filt_ttywrite(struct knote *kn, long hint)
1327{
1328 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1329

--- 1030 unchanged lines hidden (view full) ---

2360ttwakeup(struct tty *tp)
2361{
2362
2363 if (SEL_WAITING(&tp->t_rsel))
2364 selwakeuppri(&tp->t_rsel, TTIPRI);
2365 if (ISSET(tp->t_state, TS_ASYNC) && tp->t_sigio != NULL)
2366 pgsigio(&tp->t_sigio, SIGIO, (tp->t_session != NULL));
2367 wakeup(TSA_HUP_OR_INPUT(tp));
1324 splx(s);
1325}
1326
1327static int
1328filt_ttywrite(struct knote *kn, long hint)
1329{
1330 struct tty *tp = ((struct cdev *)kn->kn_hook)->si_tty;
1331

--- 1030 unchanged lines hidden (view full) ---

2362ttwakeup(struct tty *tp)
2363{
2364
2365 if (SEL_WAITING(&tp->t_rsel))
2366 selwakeuppri(&tp->t_rsel, TTIPRI);
2367 if (ISSET(tp->t_state, TS_ASYNC) && tp->t_sigio != NULL)
2368 pgsigio(&tp->t_sigio, SIGIO, (tp->t_session != NULL));
2369 wakeup(TSA_HUP_OR_INPUT(tp));
2368 KNOTE(&tp->t_rsel.si_note, 0);
2370 KNOTE_UNLOCKED(&tp->t_rsel.si_note, 0);
2369}
2370
2371/*
2372 * Wake up any writers on a tty.
2373 */
2374void
2375ttwwakeup(struct tty *tp)
2376{

--- 7 unchanged lines hidden (view full) ---

2384 CLR(tp->t_state, TS_SO_OCOMPLETE);
2385 wakeup(TSA_OCOMPLETE(tp));
2386 }
2387 if (ISSET(tp->t_state, TS_SO_OLOWAT) &&
2388 tp->t_outq.c_cc <= tp->t_olowat) {
2389 CLR(tp->t_state, TS_SO_OLOWAT);
2390 wakeup(TSA_OLOWAT(tp));
2391 }
2371}
2372
2373/*
2374 * Wake up any writers on a tty.
2375 */
2376void
2377ttwwakeup(struct tty *tp)
2378{

--- 7 unchanged lines hidden (view full) ---

2386 CLR(tp->t_state, TS_SO_OCOMPLETE);
2387 wakeup(TSA_OCOMPLETE(tp));
2388 }
2389 if (ISSET(tp->t_state, TS_SO_OLOWAT) &&
2390 tp->t_outq.c_cc <= tp->t_olowat) {
2391 CLR(tp->t_state, TS_SO_OLOWAT);
2392 wakeup(TSA_OLOWAT(tp));
2393 }
2392 KNOTE(&tp->t_wsel.si_note, 0);
2394 KNOTE_UNLOCKED(&tp->t_wsel.si_note, 0);
2393}
2394
2395/*
2396 * Look up a code for a specified speed in a conversion table;
2397 * used by drivers to map software speed values to hardware parameters.
2398 */
2399int
2400ttspeedtab(int speed, struct speedtab *table)

--- 348 unchanged lines hidden (view full) ---

2749 if (i != 0) {
2750 mtx_unlock(&tp->t_mtx);
2751 mtx_unlock(&tty_list_mutex);
2752 return (i);
2753 }
2754 TAILQ_REMOVE(&tty_list, tp, t_list);
2755 mtx_unlock(&tp->t_mtx);
2756 mtx_unlock(&tty_list_mutex);
2395}
2396
2397/*
2398 * Look up a code for a specified speed in a conversion table;
2399 * used by drivers to map software speed values to hardware parameters.
2400 */
2401int
2402ttspeedtab(int speed, struct speedtab *table)

--- 348 unchanged lines hidden (view full) ---

2751 if (i != 0) {
2752 mtx_unlock(&tp->t_mtx);
2753 mtx_unlock(&tty_list_mutex);
2754 return (i);
2755 }
2756 TAILQ_REMOVE(&tty_list, tp, t_list);
2757 mtx_unlock(&tp->t_mtx);
2758 mtx_unlock(&tty_list_mutex);
2759 knlist_destroy(&tp->t_rsel.si_note);
2760 knlist_destroy(&tp->t_wsel.si_note);
2757 mtx_destroy(&tp->t_mtx);
2758 free(tp, M_TTYS);
2759 return (i);
2760}
2761
2762/*
2763 * Allocate a tty struct. Clists in the struct will be allocated by
2764 * tty_open().

--- 19 unchanged lines hidden (view full) ---

2784 tp = malloc(sizeof *tp, M_TTYS, M_WAITOK | M_ZERO);
2785 tp->t_timeout = -1;
2786 tp->t_dtr_wait = 3 * hz;
2787 mtx_init(&tp->t_mtx, "tty", NULL, MTX_DEF);
2788 tp->t_refcnt = 1;
2789 mtx_lock(&tty_list_mutex);
2790 TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
2791 mtx_unlock(&tty_list_mutex);
2761 mtx_destroy(&tp->t_mtx);
2762 free(tp, M_TTYS);
2763 return (i);
2764}
2765
2766/*
2767 * Allocate a tty struct. Clists in the struct will be allocated by
2768 * tty_open().

--- 19 unchanged lines hidden (view full) ---

2788 tp = malloc(sizeof *tp, M_TTYS, M_WAITOK | M_ZERO);
2789 tp->t_timeout = -1;
2790 tp->t_dtr_wait = 3 * hz;
2791 mtx_init(&tp->t_mtx, "tty", NULL, MTX_DEF);
2792 tp->t_refcnt = 1;
2793 mtx_lock(&tty_list_mutex);
2794 TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
2795 mtx_unlock(&tty_list_mutex);
2796 knlist_init(&tp->t_rsel.si_note, &tp->t_mtx);
2797 knlist_init(&tp->t_wsel.si_note, &tp->t_mtx);
2792 return (tp);
2793}
2794
2795static int
2796sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
2797{
2798 struct tty *tp, *tp2;
2799 struct xtty xt;

--- 199 unchanged lines hidden ---
2798 return (tp);
2799}
2800
2801static int
2802sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
2803{
2804 struct tty *tp, *tp2;
2805 struct xtty xt;

--- 199 unchanged lines hidden ---