Deleted Added
full compact
tty.c (9626) tty.c (9639)
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.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
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.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
39 * $Id: tty.c,v 1.55 1995/07/21 22:51:50 bde Exp $
39 * $Id: tty.c,v 1.56 1995/07/22 01:30:31 bde Exp $
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

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

956 pgsignal(tp->t_pgrp, SIGWINCH, 1);
957 }
958 break;
959 case TIOCSDRAINWAIT:
960 error = suser(p->p_ucred, &p->p_acflag);
961 if (error)
962 return (error);
963 tp->t_timeout = *(int *)data * hz;
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

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

956 pgsignal(tp->t_pgrp, SIGWINCH, 1);
957 }
958 break;
959 case TIOCSDRAINWAIT:
960 error = suser(p->p_ucred, &p->p_acflag);
961 if (error)
962 return (error);
963 tp->t_timeout = *(int *)data * hz;
964 wakeup((caddr_t)&tp->t_outq);
964 wakeup(TSA_OLOWAT(tp));
965 break;
966 case TIOCGDRAINWAIT:
967 *(int *)data = tp->t_timeout / hz;
968 break;
969 default:
970#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
971 return (ttcompat(tp, cmd, data, flag));
972#else

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

1072 * wakeups for output below low water when we only care
1073 * about output complete.
1074 */
1075 if (!ISSET(tp->t_state, TS_BUSY))
1076 (*tp->t_oproc)(tp);
1077 if ((tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)) &&
1078 (ISSET(tp->t_state, TS_CARR_ON) || ISSET(tp->t_cflag, CLOCAL))) {
1079 SET(tp->t_state, TS_ASLEEP);
965 break;
966 case TIOCGDRAINWAIT:
967 *(int *)data = tp->t_timeout / hz;
968 break;
969 default:
970#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
971 return (ttcompat(tp, cmd, data, flag));
972#else

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

1072 * wakeups for output below low water when we only care
1073 * about output complete.
1074 */
1075 if (!ISSET(tp->t_state, TS_BUSY))
1076 (*tp->t_oproc)(tp);
1077 if ((tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)) &&
1078 (ISSET(tp->t_state, TS_CARR_ON) || ISSET(tp->t_cflag, CLOCAL))) {
1079 SET(tp->t_state, TS_ASLEEP);
1080 error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH,
1080 error = ttysleep(tp, TSA_OLOWAT(tp), TTOPRI | PCATCH,
1081 "ttywai", tp->t_timeout);
1082 if (error == EWOULDBLOCK)
1083 error = EIO;
1084 if (error)
1085 break;
1086 }
1087 }
1088 if (!error && (tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)))

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

1128 FLUSHQ(&tp->t_rawq);
1129 tp->t_rocount = 0;
1130 tp->t_rocol = 0;
1131 CLR(tp->t_state, TS_LOCAL);
1132 ttwakeup(tp);
1133 }
1134 if (rw & FWRITE) {
1135 FLUSHQ(&tp->t_outq);
1081 "ttywai", tp->t_timeout);
1082 if (error == EWOULDBLOCK)
1083 error = EIO;
1084 if (error)
1085 break;
1086 }
1087 }
1088 if (!error && (tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)))

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

1128 FLUSHQ(&tp->t_rawq);
1129 tp->t_rocount = 0;
1130 tp->t_rocol = 0;
1131 CLR(tp->t_state, TS_LOCAL);
1132 ttwakeup(tp);
1133 }
1134 if (rw & FWRITE) {
1135 FLUSHQ(&tp->t_outq);
1136 wakeup((caddr_t)&tp->t_outq);
1136 wakeup(TSA_OLOWAT(tp));
1137 selwakeup(&tp->t_wsel);
1138 }
1139 if ((rw & FREAD) &&
1140 ISSET(tp->t_state, TS_TBLOCK) && tp->t_rawq.c_cc < TTYHOG/5) {
1141 int queue_full = 0;
1142
1143 if (ISSET(tp->t_iflag, IXOFF) &&
1144 tp->t_cc[VSTART] != _POSIX_VDISABLE &&

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

1509 if (qp->c_cc <= 0) {
1510sleep:
1511 carrier = ISSET(tp->t_state, TS_CARR_ON) ||
1512 ISSET(tp->t_cflag, CLOCAL);
1513 if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) {
1514 splx(s);
1515 return (0); /* EOF */
1516 }
1137 selwakeup(&tp->t_wsel);
1138 }
1139 if ((rw & FREAD) &&
1140 ISSET(tp->t_state, TS_TBLOCK) && tp->t_rawq.c_cc < TTYHOG/5) {
1141 int queue_full = 0;
1142
1143 if (ISSET(tp->t_iflag, IXOFF) &&
1144 tp->t_cc[VSTART] != _POSIX_VDISABLE &&

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

1509 if (qp->c_cc <= 0) {
1510sleep:
1511 carrier = ISSET(tp->t_state, TS_CARR_ON) ||
1512 ISSET(tp->t_cflag, CLOCAL);
1513 if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) {
1514 splx(s);
1515 return (0); /* EOF */
1516 }
1517 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
1517 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
1518 carrier ?
1519 "ttyin" : "ttyhup", (int)slp);
1520 splx(s);
1521 if (error == EWOULDBLOCK)
1522 error = 0;
1523 else if (error)
1524 return (error);
1525 /*

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

1665 ttstart(tp);
1666 if (wait == 0 || curproc->p_siglist != oldsig) {
1667 splx(s);
1668 return (0);
1669 }
1670 timeout((void (*)__P((void *)))wakeup,
1671 (void *)&tp->t_outq, hz);
1672 SET(tp->t_state, TS_ASLEEP);
1518 carrier ?
1519 "ttyin" : "ttyhup", (int)slp);
1520 splx(s);
1521 if (error == EWOULDBLOCK)
1522 error = 0;
1523 else if (error)
1524 return (error);
1525 /*

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

1665 ttstart(tp);
1666 if (wait == 0 || curproc->p_siglist != oldsig) {
1667 splx(s);
1668 return (0);
1669 }
1670 timeout((void (*)__P((void *)))wakeup,
1671 (void *)&tp->t_outq, hz);
1672 SET(tp->t_state, TS_ASLEEP);
1673 (void) tsleep((caddr_t)&tp->t_outq, PZERO - 1, "ttoutq", 0);
1673 (void) tsleep(TSA_OLOWAT(tp), PZERO - 1, "ttoutq", 0);
1674 }
1675 splx(s);
1676 return (1);
1677}
1678
1679/*
1680 * Process a write call on a tty device.
1681 */

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

1702 if (ISSET(tp->t_state, TS_ISOPEN)) {
1703 splx(s);
1704 return (EIO);
1705 } else if (flag & IO_NDELAY) {
1706 splx(s);
1707 error = EWOULDBLOCK;
1708 goto out;
1709 } else {
1674 }
1675 splx(s);
1676 return (1);
1677}
1678
1679/*
1680 * Process a write call on a tty device.
1681 */

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

1702 if (ISSET(tp->t_state, TS_ISOPEN)) {
1703 splx(s);
1704 return (EIO);
1705 } else if (flag & IO_NDELAY) {
1706 splx(s);
1707 error = EWOULDBLOCK;
1708 goto out;
1709 } else {
1710 /* Sleep awaiting carrier. */
1711 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
1710 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
1712 "ttydcd", 0);
1713 splx(s);
1714 if (error)
1715 goto out;
1716 goto loop;
1717 }
1718 }
1719 splx(s);

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

1858 goto loop;
1859 }
1860 if (flag & IO_NDELAY) {
1861 splx(s);
1862 uio->uio_resid += cc;
1863 return (uio->uio_resid == cnt ? EWOULDBLOCK : 0);
1864 }
1865 SET(tp->t_state, TS_ASLEEP);
1711 "ttydcd", 0);
1712 splx(s);
1713 if (error)
1714 goto out;
1715 goto loop;
1716 }
1717 }
1718 splx(s);

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

1857 goto loop;
1858 }
1859 if (flag & IO_NDELAY) {
1860 splx(s);
1861 uio->uio_resid += cc;
1862 return (uio->uio_resid == cnt ? EWOULDBLOCK : 0);
1863 }
1864 SET(tp->t_state, TS_ASLEEP);
1866 error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH, "ttywri", tp->t_timeout);
1865 error = ttysleep(tp, TSA_OLOWAT(tp), TTOPRI | PCATCH, "ttywri",
1866 tp->t_timeout);
1867 splx(s);
1868 if (error == EWOULDBLOCK)
1869 error = EIO;
1870 if (error)
1871 goto out;
1872 goto loop;
1873}
1874

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

2045void
2046ttwakeup(tp)
2047 register struct tty *tp;
2048{
2049
2050 selwakeup(&tp->t_rsel);
2051 if (ISSET(tp->t_state, TS_ASYNC))
2052 pgsignal(tp->t_pgrp, SIGIO, 1);
1867 splx(s);
1868 if (error == EWOULDBLOCK)
1869 error = EIO;
1870 if (error)
1871 goto out;
1872 goto loop;
1873}
1874

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

2045void
2046ttwakeup(tp)
2047 register struct tty *tp;
2048{
2049
2050 selwakeup(&tp->t_rsel);
2051 if (ISSET(tp->t_state, TS_ASYNC))
2052 pgsignal(tp->t_pgrp, SIGIO, 1);
2053 wakeup((caddr_t)&tp->t_rawq);
2053 wakeup(TSA_CARR_ON(tp));
2054}
2055
2056/*
2057 * Wake up any writers on a tty.
2058 */
2059void
2060ttwwakeup(tp)
2061 register struct tty *tp;
2062{
2063
2064 if (tp->t_outq.c_cc <= tp->t_lowat) {
2065 if (tp->t_state & TS_ASLEEP) {
2066 tp->t_state &= ~TS_ASLEEP;
2054}
2055
2056/*
2057 * Wake up any writers on a tty.
2058 */
2059void
2060ttwwakeup(tp)
2061 register struct tty *tp;
2062{
2063
2064 if (tp->t_outq.c_cc <= tp->t_lowat) {
2065 if (tp->t_state & TS_ASLEEP) {
2066 tp->t_state &= ~TS_ASLEEP;
2067 wakeup(&tp->t_outq);
2067 wakeup(TSA_OLOWAT(tp));
2068 }
2069 selwakeup(&tp->t_wsel);
2070 }
2071}
2072
2073/*
2074 * Look up a code for a specified speed in a conversion table;
2075 * used by drivers to map software speed values to hardware parameters.

--- 245 unchanged lines hidden ---
2068 }
2069 selwakeup(&tp->t_wsel);
2070 }
2071}
2072
2073/*
2074 * Look up a code for a specified speed in a conversion table;
2075 * used by drivers to map software speed values to hardware parameters.

--- 245 unchanged lines hidden ---