tty.c (9622) | tty.c (9624) |
---|---|
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.52 1995/07/21 16:30:51 bde Exp $ | 39 * $Id: tty.c,v 1.53 1995/07/21 17:30:12 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. --- 46 unchanged lines hidden (view full) --- 94 95 96static int proc_compare __P((struct proc *p1, struct proc *p2)); 97static int ttnread __P((struct tty *)); 98static void ttyblock __P((struct tty *tp)); 99static void ttyecho __P((int, struct tty *tp)); 100static void ttyrubo __P((struct tty *, int)); 101 | 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. --- 46 unchanged lines hidden (view full) --- 94 95 96static int proc_compare __P((struct proc *p1, struct proc *p2)); 97static int ttnread __P((struct tty *)); 98static void ttyblock __P((struct tty *tp)); 99static void ttyecho __P((int, struct tty *tp)); 100static void ttyrubo __P((struct tty *, int)); 101 |
102/* Symbolic sleep message strings. */ 103char ttclos[] = "ttycls"; 104char ttopen[] = "ttyopn"; 105char ttybg[] = "ttybg"; 106char ttybuf[] = "ttybuf"; 107char ttyin[] = "ttyin"; 108char ttyout[] = "ttyout"; 109 | |
110/* 111 * Table with character classes and parity. The 8th bit indicates parity, 112 * the 7th bit indicates the character is an alphameric or underscore (for 113 * ALTWERASE), and the low 6 bits indicate delay type. If the low 6 bits 114 * are 0 then the character needs no special processing on output; classes 115 * other than 0 might be translated or (not currently) require delays. 116 */ 117#define E 0x00 /* Even parity. */ --- 597 unchanged lines hidden (view full) --- 715 case TIOCSETP: 716 case TIOCSLTC: 717#endif 718 while (isbackground(curproc, tp) && 719 p->p_pgrp->pg_jobc && (p->p_flag & P_PPWAIT) == 0 && 720 (p->p_sigignore & sigmask(SIGTTOU)) == 0 && 721 (p->p_sigmask & sigmask(SIGTTOU)) == 0) { 722 pgsignal(p->p_pgrp, SIGTTOU, 1); | 102/* 103 * Table with character classes and parity. The 8th bit indicates parity, 104 * the 7th bit indicates the character is an alphameric or underscore (for 105 * ALTWERASE), and the low 6 bits indicate delay type. If the low 6 bits 106 * are 0 then the character needs no special processing on output; classes 107 * other than 0 might be translated or (not currently) require delays. 108 */ 109#define E 0x00 /* Even parity. */ --- 597 unchanged lines hidden (view full) --- 707 case TIOCSETP: 708 case TIOCSLTC: 709#endif 710 while (isbackground(curproc, tp) && 711 p->p_pgrp->pg_jobc && (p->p_flag & P_PPWAIT) == 0 && 712 (p->p_sigignore & sigmask(SIGTTOU)) == 0 && 713 (p->p_sigmask & sigmask(SIGTTOU)) == 0) { 714 pgsignal(p->p_pgrp, SIGTTOU, 1); |
723 error = ttysleep(tp, &lbolt, TTOPRI | PCATCH, ttybg, 0); | 715 error = ttysleep(tp, &lbolt, TTOPRI | PCATCH, "ttybg1", 716 0); |
724 if (error) 725 return (error); 726 } 727 break; 728 } 729 730 switch (cmd) { /* Process the ioctl. */ 731 case FIOASYNC: /* set/clear async i/o */ --- 649 unchanged lines hidden (view full) --- 1381 */ 1382 if (isbackground(p, tp)) { 1383 splx(s); 1384 if ((p->p_sigignore & sigmask(SIGTTIN)) || 1385 (p->p_sigmask & sigmask(SIGTTIN)) || 1386 p->p_flag & P_PPWAIT || p->p_pgrp->pg_jobc == 0) 1387 return (EIO); 1388 pgsignal(p->p_pgrp, SIGTTIN, 1); | 717 if (error) 718 return (error); 719 } 720 break; 721 } 722 723 switch (cmd) { /* Process the ioctl. */ 724 case FIOASYNC: /* set/clear async i/o */ --- 649 unchanged lines hidden (view full) --- 1374 */ 1375 if (isbackground(p, tp)) { 1376 splx(s); 1377 if ((p->p_sigignore & sigmask(SIGTTIN)) || 1378 (p->p_sigmask & sigmask(SIGTTIN)) || 1379 p->p_flag & P_PPWAIT || p->p_pgrp->pg_jobc == 0) 1380 return (EIO); 1381 pgsignal(p->p_pgrp, SIGTTIN, 1); |
1389 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0); | 1382 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, "ttybg2", 0); |
1390 if (error) 1391 return (error); 1392 goto loop; 1393 } 1394 1395 /* 1396 * If canonical, use the canonical queue, 1397 * else use the raw queue. --- 108 unchanged lines hidden (view full) --- 1506sleep: 1507 carrier = ISSET(tp->t_state, TS_CARR_ON) || 1508 ISSET(tp->t_cflag, CLOCAL); 1509 if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) { 1510 splx(s); 1511 return (0); /* EOF */ 1512 } 1513 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH, | 1383 if (error) 1384 return (error); 1385 goto loop; 1386 } 1387 1388 /* 1389 * If canonical, use the canonical queue, 1390 * else use the raw queue. --- 108 unchanged lines hidden (view full) --- 1499sleep: 1500 carrier = ISSET(tp->t_state, TS_CARR_ON) || 1501 ISSET(tp->t_cflag, CLOCAL); 1502 if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) { 1503 splx(s); 1504 return (0); /* EOF */ 1505 } 1506 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH, |
1514 carrier ? ttyin : ttopen, (int)slp); | 1507 carrier ? 1508 "ttyin" : "ttyhup", (int)slp); |
1515 splx(s); 1516 if (error == EWOULDBLOCK) 1517 error = 0; 1518 else if (error) 1519 return (error); 1520 /* 1521 * XXX what happens if another process eats some input 1522 * while we are asleep (not just here)? It would be --- 48 unchanged lines hidden (view full) --- 1571 break; 1572 } 1573 /* 1574 * delayed suspend (^Y) 1575 */ 1576 if (CCEQ(cc[VDSUSP], c) && ISSET(lflag, ISIG)) { 1577 pgsignal(tp->t_pgrp, SIGTSTP, 1); 1578 if (first) { | 1509 splx(s); 1510 if (error == EWOULDBLOCK) 1511 error = 0; 1512 else if (error) 1513 return (error); 1514 /* 1515 * XXX what happens if another process eats some input 1516 * while we are asleep (not just here)? It would be --- 48 unchanged lines hidden (view full) --- 1565 break; 1566 } 1567 /* 1568 * delayed suspend (^Y) 1569 */ 1570 if (CCEQ(cc[VDSUSP], c) && ISSET(lflag, ISIG)) { 1571 pgsignal(tp->t_pgrp, SIGTSTP, 1); 1572 if (first) { |
1579 error = ttysleep(tp, 1580 &lbolt, TTIPRI | PCATCH, ttybg, 0); | 1573 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, 1574 "ttybg3", 0); |
1581 if (error) 1582 break; 1583 goto loop; 1584 } 1585 break; 1586 } 1587 /* 1588 * Interpret EOF only in canonical mode. --- 109 unchanged lines hidden (view full) --- 1698 splx(s); 1699 return (EIO); 1700 } else if (flag & IO_NDELAY) { 1701 splx(s); 1702 error = EWOULDBLOCK; 1703 goto out; 1704 } else { 1705 /* Sleep awaiting carrier. */ | 1575 if (error) 1576 break; 1577 goto loop; 1578 } 1579 break; 1580 } 1581 /* 1582 * Interpret EOF only in canonical mode. --- 109 unchanged lines hidden (view full) --- 1692 splx(s); 1693 return (EIO); 1694 } else if (flag & IO_NDELAY) { 1695 splx(s); 1696 error = EWOULDBLOCK; 1697 goto out; 1698 } else { 1699 /* Sleep awaiting carrier. */ |
1706 error = ttysleep(tp, 1707 &tp->t_rawq, TTIPRI | PCATCH,ttopen, 0); | 1700 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH, 1701 "ttydcd", 0); |
1708 splx(s); 1709 if (error) 1710 goto out; 1711 goto loop; 1712 } 1713 } 1714 splx(s); 1715 /* 1716 * Hang the process if it's in the background. 1717 */ 1718 p = curproc; 1719 if (isbackground(p, tp) && 1720 ISSET(tp->t_lflag, TOSTOP) && (p->p_flag & P_PPWAIT) == 0 && 1721 (p->p_sigignore & sigmask(SIGTTOU)) == 0 && 1722 (p->p_sigmask & sigmask(SIGTTOU)) == 0 && 1723 p->p_pgrp->pg_jobc) { 1724 pgsignal(p->p_pgrp, SIGTTOU, 1); | 1702 splx(s); 1703 if (error) 1704 goto out; 1705 goto loop; 1706 } 1707 } 1708 splx(s); 1709 /* 1710 * Hang the process if it's in the background. 1711 */ 1712 p = curproc; 1713 if (isbackground(p, tp) && 1714 ISSET(tp->t_lflag, TOSTOP) && (p->p_flag & P_PPWAIT) == 0 && 1715 (p->p_sigignore & sigmask(SIGTTOU)) == 0 && 1716 (p->p_sigmask & sigmask(SIGTTOU)) == 0 && 1717 p->p_pgrp->pg_jobc) { 1718 pgsignal(p->p_pgrp, SIGTTOU, 1); |
1725 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0); | 1719 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, "ttybg4", 0); |
1726 if (error) 1727 goto out; 1728 goto loop; 1729 } 1730 /* 1731 * Process the user's data in at most OBUFSIZ chunks. Perform any 1732 * output translation. Keep track of high water mark, sleep on 1733 * overflow awaiting device aid in acquiring new space. --- 46 unchanged lines hidden (view full) --- 1780 if (ttyoutput(*cp, tp) >= 0) { 1781 /* No Clists, wait a bit. */ 1782 ttstart(tp); 1783 if (flag & IO_NDELAY) { 1784 error = EWOULDBLOCK; 1785 goto out; 1786 } 1787 error = ttysleep(tp, &lbolt, | 1720 if (error) 1721 goto out; 1722 goto loop; 1723 } 1724 /* 1725 * Process the user's data in at most OBUFSIZ chunks. Perform any 1726 * output translation. Keep track of high water mark, sleep on 1727 * overflow awaiting device aid in acquiring new space. --- 46 unchanged lines hidden (view full) --- 1774 if (ttyoutput(*cp, tp) >= 0) { 1775 /* No Clists, wait a bit. */ 1776 ttstart(tp); 1777 if (flag & IO_NDELAY) { 1778 error = EWOULDBLOCK; 1779 goto out; 1780 } 1781 error = ttysleep(tp, &lbolt, |
1788 TTOPRI | PCATCH, ttybuf, 0); | 1782 TTOPRI|PCATCH, 1783 "ttybf1", 0); |
1789 if (error) 1790 goto out; 1791 goto loop; 1792 } 1793 cp++; 1794 cc--; 1795 if (ISSET(tp->t_lflag, FLUSHO) || 1796 tp->t_outq.c_cc > hiwat) --- 17 unchanged lines hidden (view full) --- 1814 tp->t_outcc += ce; 1815 if (i > 0) { 1816 /* No Clists, wait a bit. */ 1817 ttstart(tp); 1818 if (flag & IO_NDELAY) { 1819 error = EWOULDBLOCK; 1820 goto out; 1821 } | 1784 if (error) 1785 goto out; 1786 goto loop; 1787 } 1788 cp++; 1789 cc--; 1790 if (ISSET(tp->t_lflag, FLUSHO) || 1791 tp->t_outq.c_cc > hiwat) --- 17 unchanged lines hidden (view full) --- 1809 tp->t_outcc += ce; 1810 if (i > 0) { 1811 /* No Clists, wait a bit. */ 1812 ttstart(tp); 1813 if (flag & IO_NDELAY) { 1814 error = EWOULDBLOCK; 1815 goto out; 1816 } |
1822 error = ttysleep(tp, 1823 &lbolt, TTOPRI | PCATCH, ttybuf, 0); | 1817 error = ttysleep(tp, &lbolt, TTOPRI | PCATCH, 1818 "ttybf2", 0); |
1824 if (error) 1825 goto out; 1826 goto loop; 1827 } 1828 if (ISSET(tp->t_lflag, FLUSHO) || 1829 tp->t_outq.c_cc > hiwat) 1830 break; 1831 } --- 466 unchanged lines hidden --- | 1819 if (error) 1820 goto out; 1821 goto loop; 1822 } 1823 if (ISSET(tp->t_lflag, FLUSHO) || 1824 tp->t_outq.c_cc > hiwat) 1825 break; 1826 } --- 466 unchanged lines hidden --- |