X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/802ce5edba3e5da4fe110a6605f8b6ad2fded4eb..943685687a914f34bb028d07fefeff4a802b6d5b:/usr/src/sys/kern/tty.c diff --git a/usr/src/sys/kern/tty.c b/usr/src/sys/kern/tty.c index cdd234d051..2b1e6fe9f0 100644 --- a/usr/src/sys/kern/tty.c +++ b/usr/src/sys/kern/tty.c @@ -1,21 +1,21 @@ -/* tty.c 4.46 83/07/06 */ +/* tty.c 6.10 84/08/29 */ #include "../machine/reg.h" -#include "../h/param.h" -#include "../h/systm.h" -#include "../h/dir.h" -#include "../h/user.h" -#include "../h/ioctl.h" -#include "../h/tty.h" -#include "../h/proc.h" -#include "../h/inode.h" -#include "../h/file.h" -#include "../h/conf.h" -#include "../h/buf.h" -#include "../h/dk.h" -#include "../h/uio.h" -#include "../h/kernel.h" +#include "param.h" +#include "systm.h" +#include "dir.h" +#include "user.h" +#include "ioctl.h" +#include "tty.h" +#include "proc.h" +#include "inode.h" +#include "file.h" +#include "conf.h" +#include "buf.h" +#include "dk.h" +#include "uio.h" +#include "kernel.h" /* * Table giving parity for characters and indicating @@ -158,7 +158,6 @@ ttyflush(tp, rw) if (rw & FREAD) { while (getc(&tp->t_rawq) >= 0) ; - tp->t_delct = 0; tp->t_rocount = 0; tp->t_rocol = 0; tp->t_state &= ~TS_LOCAL; @@ -179,9 +178,16 @@ ttyblock(tp) ttyflush(tp, FREAD|FWRITE); tp->t_state &= ~TS_TBLOCK; } - if (x >= TTYHOG/2 && putc(tp->t_stopc, &tp->t_outq) == 0) { - tp->t_state |= TS_TBLOCK; - ttstart(tp); + /* + * Block further input iff: + * Current input > threshold AND input is available to user program + */ + if (x >= TTYHOG/2 && + ((tp->t_flags & (RAW|CBREAK)) || (tp->t_canq.c_cc > 0))) { + if (putc(tp->t_stopc, &tp->t_outq)==0) { + tp->t_state |= TS_TBLOCK; + ttstart(tp); + } } } @@ -250,16 +256,18 @@ ttioctl(tp, com, data, flag) case TIOCLBIC: case TIOCLSET: case TIOCSTI: +#define bit(a) (1<<(a-1)) while (tp->t_line == NTTYDISC && u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && (u.u_procp->p_flag&SVFORK) == 0 && - u.u_signal[SIGTTOU] != SIG_IGN && - u.u_signal[SIGTTOU] != SIG_HOLD) { + !(u.u_procp->p_sigignore & bit(SIGTTOU)) && + !(u.u_procp->p_sigmask & bit(SIGTTOU))) { gsignal(u.u_procp->p_pgrp, SIGTTOU); sleep((caddr_t)&lbolt, TTOPRI); } break; } +#undef bit /* * Process the ioctl. @@ -276,7 +284,7 @@ ttioctl(tp, com, data, flag) register int t = *(int *)data; int error = 0; - if (t >= nldisp) + if ((unsigned) t >= nldisp) return (ENXIO); s = spl5(); if (tp->t_line) @@ -453,7 +461,7 @@ ttioctl(tp, com, data, flag) break; case TIOCLGET: - *(int *)data = tp->t_flags >> 16; + *(int *)data = ((unsigned) tp->t_flags) >> 16; break; /* should allow SPGRP and GPGRP only if tty open for reading */ @@ -939,13 +947,20 @@ ttyoutput(c, tp) (*colp)--; break; + /* + * This macro is close enough to the correct thing; + * it should be replaced by real user settable delays + * in any event... + */ +#define mstohz(ms) (((ms) * hz) >> 10) case NEWLINE: ctype = (tp->t_flags >> 8) & 03; if (ctype == 1) { /* tty 37 */ if (*colp > 0) - c = max(((unsigned)*colp>>4) + 3, (unsigned)6); + c = max((((unsigned)*colp) >> 4) + 3, + (unsigned)6); } else if (ctype == 2) /* vt05 */ - c = 6; + c = mstohz(100); *colp = 0; break; @@ -968,9 +983,9 @@ ttyoutput(c, tp) case RETURN: ctype = (tp->t_flags >> 12) & 03; if (ctype == 1) /* tn 300 */ - c = 5; + c = mstohz(83); else if (ctype == 2) /* ti 700 */ - c = 10; + c = mstohz(166); else if (ctype == 3) { /* concept 100 */ int i; @@ -984,6 +999,7 @@ ttyoutput(c, tp) (void) putc(c|0200, &tp->t_outq); return (-1); } +#undef mstohz /* * Called from device's read routine after it has @@ -1011,9 +1027,10 @@ loop: /* * Hang process if it's in the background. */ +#define bit(a) (1<<(a-1)) while (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) { - if (u.u_signal[SIGTTIN] == SIG_IGN || - u.u_signal[SIGTTIN] == SIG_HOLD || + if ((u.u_procp->p_sigignore & bit(SIGTTIN)) || + (u.u_procp->p_sigmask & bit(SIGTTIN)) || /* (u.u_procp->p_flag&SDETACH) || */ @@ -1023,6 +1040,7 @@ loop: sleep((caddr_t)&lbolt, TTIPRI); } t_flags = tp->t_flags; +#undef bit /* * In raw mode take characters directly from the @@ -1035,15 +1053,15 @@ loop: if ((tp->t_state&TS_CARR_ON) == 0 || (tp->t_state&TS_NBIO)) { splx(s); - return (0); + return (EWOULDBLOCK); } sleep((caddr_t)&tp->t_rawq, TTIPRI); splx(s); goto loop; } splx(s); - while (!error && tp->t_rawq.c_cc && uio->uio_iovcnt) - error = passuc(getc(&tp->t_rawq), uio); + while (!error && tp->t_rawq.c_cc && uio->uio_resid) + error = ureadc(getc(&tp->t_rawq), uio); goto checktandem; } @@ -1112,10 +1130,10 @@ loop: /* * Give user character. */ - error = passuc(c & 0177, uio); + error = ureadc(c & 0177, uio); if (error) break; - if (uio->uio_iovcnt == 0) + if (uio->uio_resid == 0) break; /* * In cooked mode check for a "break character" @@ -1162,10 +1180,11 @@ loop: /* * Hang the process if it's in the background. */ +#define bit(a) (1<<(a-1)) while (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && (tp->t_flags&TOSTOP) && (u.u_procp->p_flag&SVFORK)==0 && - u.u_signal[SIGTTOU] != SIG_IGN && - u.u_signal[SIGTTOU] != SIG_HOLD + !(u.u_procp->p_sigignore & bit(SIGTTOU)) && + !(u.u_procp->p_sigmask & bit(SIGTTOU)) /* && (u.u_procp->p_flag&SDETACH)==0) { @@ -1174,6 +1193,7 @@ loop: gsignal(u.u_procp->p_pgrp, SIGTTOU); sleep((caddr_t)&lbolt, TTIPRI); } +#undef bit /* * Process the user's data in at most OBUFSIZ @@ -1520,6 +1540,6 @@ scanc(size, cp, table, mask) while ((table[*(u_char *)(cp + i)]&mask) == 0 && i < size) i++; - return (i); + return (size - i); } #endif