--- Net2/kern/tty_pty.c 2018/04/24 18:03:57 1.1 +++ Net2/kern/tty_pty.c 2018/04/24 18:09:09 1.1.1.4 @@ -31,7 +31,23 @@ * SUCH DAMAGE. * * @(#)tty_pty.c 7.21 (Berkeley) 5/30/91 + * + * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE + * -------------------- ----- ---------------------- + * CURRENT PATCH LEVEL: 5 00094 + * -------------------- ----- ---------------------- + * + * 11 Dec 92 Williams Jolitz Fixed tty handling + * + * 28 Nov 1991 Warren Toomey Cleaned up the use of COMPAT_43 + * in the 386BSD kernel. + * 6 Oct 1992 Holger Veit Fixed 'hanging console' bug + * 11 Jan 93 Julian Elischer Fixes multiple processes on one + * pty bug + * 27 Feb 93 Charles Hannum Proper return values for ptsclose() + * and ptcclose() */ +static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/kern/tty_pty.c,v 1.1.1.4 2018/04/24 18:09:09 root Exp $"; /* * Pseudo-teletype Driver @@ -65,7 +81,7 @@ struct tty pt_tty[NPTY]; struct pt_ioctl { int pt_flags; - struct proc *pt_selr, *pt_selw; + pid_t pt_selr, pt_selw; u_char pt_send; u_char pt_ucntl; } pt_ioctl[NPTY]; @@ -110,7 +126,7 @@ ptsopen(dev, flag, devtype, p) tp->t_state |= TS_WOPEN; if (flag&FNONBLOCK) break; - if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, + if (error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, ttopen, 0)) return (error); } @@ -130,6 +146,7 @@ ptsclose(dev, flag, mode, p) (*linesw[tp->t_line].l_close)(tp, flag); ttyclose(tp); ptcwakeup(tp, FREAD|FWRITE); + return(0); } ptsread(dev, uio, flag) @@ -154,22 +171,22 @@ again: TTIPRI | PCATCH, ttybg, 0)) return (error); } - if (tp->t_canq.c_cc == 0) { + if (RB_LEN(&tp->t_can) == 0) { if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = ttysleep(tp, (caddr_t)&tp->t_canq, + if (error = ttysleep(tp, (caddr_t)&tp->t_can, TTIPRI | PCATCH, ttyin, 0)) return (error); goto again; } - while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0) - if (ureadc(getc(&tp->t_canq), uio) < 0) { + while (RB_LEN(&tp->t_can) > 1 && uio->uio_resid > 0) + if (ureadc(getc(&tp->t_can), uio) < 0) { error = EFAULT; break; } - if (tp->t_canq.c_cc == 1) - (void) getc(&tp->t_canq); - if (tp->t_canq.c_cc) + if (RB_LEN(&tp->t_can) == 1) + (void) getc(&tp->t_can); + if (RB_LEN(&tp->t_can)) return (error); } else if (tp->t_oproc) @@ -224,7 +241,7 @@ ptcwakeup(tp, flag) pti->pt_selr = 0; pti->pt_flags &= ~PF_RCOLL; } - wakeup((caddr_t)&tp->t_outq.c_cf); + wakeup((caddr_t)&tp->t_out.rb_tl); } if (flag & FWRITE) { if (pti->pt_selw) { @@ -232,7 +249,7 @@ ptcwakeup(tp, flag) pti->pt_selw = 0; pti->pt_flags &= ~PF_WCOLL; } - wakeup((caddr_t)&tp->t_rawq.c_cf); + wakeup((caddr_t)&tp->t_raw.rb_hd); } } @@ -264,6 +281,7 @@ ptcopen(dev, flag, devtype, p) return (0); } +extern struct tty *constty; /* -hv- 06.Oct.92*/ ptcclose(dev) dev_t dev; { @@ -274,6 +292,12 @@ ptcclose(dev) tp->t_state &= ~TS_CARR_ON; tp->t_oproc = 0; /* mark closed */ tp->t_session = 0; + +/* XXX -hv- 6.Oct.92 this prevents the "hanging console bug" with X11 */ + if (constty==tp) + constty = 0; + + return (0); } ptcread(dev, uio, flag) @@ -312,29 +336,38 @@ ptcread(dev, uio, flag) pti->pt_ucntl = 0; return (0); } - if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) + if (RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) break; } if ((tp->t_state&TS_CARR_ON) == 0) return (0); /* EOF */ if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = tsleep((caddr_t)&tp->t_outq.c_cf, TTIPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_out.rb_tl, TTIPRI | PCATCH, ttyin, 0)) return (error); } if (pti->pt_flags & (PF_PKT|PF_UCNTL)) error = ureadc(0, uio); while (uio->uio_resid > 0 && error == 0) { +#ifdef was cc = q_to_b(&tp->t_outq, buf, MIN(uio->uio_resid, BUFSIZ)); +#else + cc = min(MIN(uio->uio_resid, BUFSIZ), RB_CONTIGGET(&tp->t_out)); + if (cc) { + bcopy(tp->t_out.rb_hd, buf, cc); + tp->t_out.rb_hd = + RB_ROLLOVER(&tp->t_out, tp->t_out.rb_hd+cc); + } +#endif if (cc <= 0) break; error = uiomove(buf, cc, uio); } - if (tp->t_outq.c_cc <= tp->t_lowat) { + if (RB_LEN(&tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); + wakeup((caddr_t)&tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -388,7 +421,7 @@ ptcselect(dev, rw, p) */ s = spltty(); if ((tp->t_state&TS_ISOPEN) && - tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) { + RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) { splx(s); return (1); } @@ -400,29 +433,29 @@ ptcselect(dev, rw, p) (pti->pt_flags&PF_PKT && pti->pt_send || pti->pt_flags&PF_UCNTL && pti->pt_ucntl)) return (1); - if ((prev = pti->pt_selr) && prev->p_wchan == (caddr_t)&selwait) + if (pti->pt_selr && (prev = pfind(pti->pt_selr)) && prev->p_wchan == (caddr_t)&selwait) pti->pt_flags |= PF_RCOLL; else - pti->pt_selr = p; + pti->pt_selr = p->p_pid; break; case FWRITE: if (tp->t_state&TS_ISOPEN) { if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc == 0) + if (RB_LEN(&tp->t_can) == 0) return (1); } else { - if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2) + if (RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can) < TTYHOG-2) return (1); - if (tp->t_canq.c_cc == 0 && (tp->t_iflag&ICANON)) + if (RB_LEN(&tp->t_can) == 0 && (tp->t_iflag&ICANON)) return (1); } } - if ((prev = pti->pt_selw) && prev->p_wchan == (caddr_t)&selwait) + if (pti->pt_selw && (prev = pfind(pti->pt_selw)) && prev->p_wchan == (caddr_t)&selwait) pti->pt_flags |= PF_WCOLL; else - pti->pt_selw = p; + pti->pt_selw = p->p_pid; break; } @@ -445,12 +478,12 @@ again: if ((tp->t_state&TS_ISOPEN) == 0) goto block; if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc) + if (RB_LEN(&tp->t_can)) goto block; - while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) { + while (uio->uio_resid > 0 && RB_LEN(&tp->t_can) < TTYHOG - 1) { if (cc == 0) { cc = min(uio->uio_resid, BUFSIZ); - cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc); + cc = min(cc, TTYHOG - 1 - RB_CONTIGPUT(&tp->t_can)); cp = locbuf; error = uiomove((caddr_t)cp, cc, uio); if (error) @@ -459,13 +492,21 @@ again: if ((tp->t_state&TS_ISOPEN) == 0) return (EIO); } +#ifdef was if (cc) (void) b_to_q((char *)cp, cc, &tp->t_canq); +#else + if (cc) { + bcopy(cp, tp->t_can.rb_tl, cc); + tp->t_can.rb_tl = + RB_ROLLOVER(&tp->t_can, tp->t_can.rb_tl+cc); + } +#endif cc = 0; } - (void) putc(0, &tp->t_canq); + (void) putc(0, &tp->t_can); ttwakeup(tp); - wakeup((caddr_t)&tp->t_canq); + wakeup((caddr_t)&tp->t_can); return (0); } while (uio->uio_resid > 0) { @@ -480,9 +521,9 @@ again: return (EIO); } while (cc > 0) { - if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && - (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { - wakeup((caddr_t)&tp->t_rawq); + if ((RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can)) >= TTYHOG - 2 && + (RB_LEN(&tp->t_can) > 0 || !(tp->t_iflag&ICANON))) { + wakeup((caddr_t)&tp->t_raw); goto block; } (*linesw[tp->t_line].l_rint)(*cp++, tp); @@ -506,7 +547,7 @@ block: return (EWOULDBLOCK); return (0); } - if (error = tsleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_raw.rb_hd, TTOPRI | PCATCH, ttyout, 0)) { /* adjust for data copied in but not written */ uio->uio_resid += cc; @@ -539,14 +580,14 @@ ptyioctl(dev, cmd, data, flag) if (*(int *)data) { if (pti->pt_flags & PF_PKT) { pti->pt_send |= TIOCPKT_IOCTL; - ptcwakeup(tp); + ptcwakeup(tp, FREAD); } tp->t_lflag |= EXTPROC; } else { if ((tp->t_state & EXTPROC) && (pti->pt_flags & PF_PKT)) { pti->pt_send |= TIOCPKT_IOCTL; - ptcwakeup(tp); + ptcwakeup(tp, FREAD); } tp->t_lflag &= ~EXTPROC; } @@ -589,13 +630,16 @@ ptyioctl(dev, cmd, data, flag) ttyflush(tp, FREAD|FWRITE); return (0); +#ifdef COMPAT_43 + /* wkt */ case TIOCSETP: case TIOCSETN: +#endif case TIOCSETD: case TIOCSETA: case TIOCSETAW: case TIOCSETAF: - while (getc(&tp->t_outq) >= 0) + while (getc(&tp->t_out) >= 0) ; break; @@ -644,9 +688,10 @@ ptyioctl(dev, cmd, data, flag) case TIOCSETA: case TIOCSETAW: case TIOCSETAF: +#ifdef COMPAT_43 + /* wkt */ case TIOCSETP: case TIOCSETN: -#ifdef COMPAT_43 case TIOCSETC: case TIOCSLTC: case TIOCLBIS: