diff options
author | ugen <ugen@FreeBSD.org> | 1995-02-15 18:41:57 +0000 |
---|---|---|
committer | ugen <ugen@FreeBSD.org> | 1995-02-15 18:41:57 +0000 |
commit | 62bf834d197b90c91a29df2fb90102092ea9b476 (patch) | |
tree | 64290d4c56e50e389748f8ec3709c66bc954783b /sys | |
parent | 868b16fdda6736719292daa6beab7e1199f6f11e (diff) | |
download | FreeBSD-src-62bf834d197b90c91a29df2fb90102092ea9b476.zip FreeBSD-src-62bf834d197b90c91a29df2fb90102092ea9b476.tar.gz |
More changes to support user calls.
It's 22:00 here,utility still to come(hopefully tomorrow
morning..)
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/snp/snp.c | 44 | ||||
-rw-r--r-- | sys/kern/tty.c | 63 | ||||
-rw-r--r-- | sys/kern/tty_snoop.c | 44 |
3 files changed, 91 insertions, 60 deletions
diff --git a/sys/dev/snp/snp.c b/sys/dev/snp/snp.c index f852a81..eaee544 100644 --- a/sys/dev/snp/snp.c +++ b/sys/dev/snp/snp.c @@ -203,6 +203,7 @@ snpin(snp, buf, n) printf("Snoop: more data to down interface.\n"); return 0; } + if (snp->snp_flags & SNOOP_OFLOW) { printf("Snoop: buffer overflow.\n"); /* @@ -212,13 +213,7 @@ snpin(snp, buf, n) * snooping and retry... */ - snp->snp_blen = SNOOP_MINLEN; - free(snp->snp_buf, M_TTYS); - snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); - snp->snp_flags |= SNOOP_DOWN; - snp->snp_flags &= ~SNOOP_OFLOW; - - return (snp_detach(snp)); + return (snpdown(snp)); } s_tail = snp->snp_blen - (snp->snp_len + snp->snp_base); s_free = snp->snp_blen - snp->snp_len; @@ -323,7 +318,7 @@ snp_detach(snp) */ if (snp->snp_unit == -1) - goto destroy_notty; + goto detach_notty; l_tty = &tty_tabs[snp->snp_type]; @@ -338,7 +333,7 @@ snp_detach(snp) snp->snp_unit = -1; -destroy_notty: +detach_notty: selwakeup(&snp->snp_sel); snp->snp_sel.si_pid = 0; @@ -360,7 +355,17 @@ snpclose(dev, flag) return (snp_detach(snp)); } +int +snpdown(snp) + struct snoop *snp; +{ + snp->snp_blen = SNOOP_MINLEN; + free(snp->snp_buf, M_TTYS); + snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); + snp->snp_flags |= SNOOP_DOWN; + return (snp_detach(snp)); +} int @@ -381,6 +386,9 @@ snpioctl(dev, cmd, data, flag) tunit = ((struct snptty *) data)->st_unit; ttype = ((struct snptty *) data)->st_type; + if (ttype == -1 || tunit == -1) + return (snpdown(snp)); + if (ttype < 0 || ttype > ST_MAXTYPE) return (EINVAL); @@ -409,6 +417,11 @@ snpioctl(dev, cmd, data, flag) tp->t_state |= TS_SNOOP; snp->snp_unit = tunit; snp->snp_type = ttype; + /* + * Clean overflow and down flags - + * we'll have a chance to get them in the future :))) + */ + snp->snp_flags &= ~SNOOP_OFLOW; snp->snp_flags &= ~SNOOP_DOWN; splx(s); @@ -434,10 +447,15 @@ snpioctl(dev, cmd, data, flag) s = spltty(); if (snp->snp_unit != -1) *(int *) data = snp->snp_len; - else if (snp->snp_flags & SNOOP_DOWN) - *(int *) data = -1; - else - *(int *) data = 0; + else + if (snp->snp_flags&SNOOP_DOWN) { + if (snp->snp_flags&SNOOP_OFLOW) + *(int *) data = SNP_OFLOW; + else + *(int *) data = SNP_TTYCLOSE; + } else { + *(int *) data = SNP_DETACH; + } splx(s); break; default: diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 27a6000..8fd5fc0 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -64,6 +64,7 @@ #include <vm/vm.h> + static int proc_compare __P((struct proc *p1, struct proc *p2)); static void ttyblock __P((struct tty *tp)); static void ttyecho __P((int, struct tty *tp)); @@ -206,6 +207,11 @@ ttyclose(tp) clist_free_cblocks(&tp->t_outq); clist_free_cblocks(&tp->t_rawq); +#if NSNP > 0 + if (ISSET(tp->t_state, TS_SNOOP) && tp->t_sc != NULL) + snpdown((struct snoop *)tp->t_sc); +#endif + tp->t_gen++; tp->t_pgrp = NULL; tp->t_session = NULL; @@ -224,22 +230,6 @@ ttyclose(tp) ((c) == '\n' || (((c) == cc[VEOF] || \ (c) == cc[VEOL] || (c) == cc[VEOL2]) && (c) != _POSIX_VDISABLE)) -/*- - * TODO: - * o Fix races for sending the start char in ttyflush(). - * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttselect(). - * With luck, there will be MIN chars before select() returns(). - * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it. - * o Don't allow input in TS_ZOMBIE case. It would be visible through - * FIONREAD. - * o Do the new sio locking stuff here and use it to avoid special - * case for EXTPROC? - * o Lock PENDIN too? - * o Move EXTPROC and/or PENDIN to t_state? - * o Wrap most of ttioctl in spltty/splx. - * o Implement TIOCNOTTY or remove it from <sys/ioctl.h>. - */ - /* * Process input of a single character received on a tty. @@ -1026,8 +1016,6 @@ ttywait(tp) break; } } - if (!error && (tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY))) - error = EIO; splx(s); return (error); } @@ -1159,8 +1147,10 @@ ttylclose(tp, flag) int flag; { - if ((flag & IO_NDELAY) || ttywflush(tp)) + if (flag & IO_NDELAY) ttyflush(tp, FREAD | FWRITE); + else + ttywflush(tp); return (0); } @@ -1619,6 +1609,7 @@ loop: if (ISSET(tp->t_state, TS_SNOOP) && tp->t_sc != NULL) snpin((struct snoop *)tp->t_sc, cp, cc); #endif + } /* * If nothing fancy need be done, grab those characters we @@ -2128,33 +2119,37 @@ ttysleep(tp, chan, pri, wmesg, timo) } /* - * XXX this is usable but not useful or used. ttselect() requires an array - * of tty structs. Most tty drivers have ifdefs for using ttymalloc() but - * assume a different interface. - */ -/* - * Allocate a tty struct. Clists in the struct will be allocated by - * ttyopen(). + * Allocate a tty structure and its associated buffers. */ struct tty * ttymalloc() { struct tty *tp; - tp = malloc(sizeof *tp, M_TTYS, M_WAITOK); + MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK); bzero(tp, sizeof *tp); - return (tp); + + /* + * Initialize or restore a cblock allocation policy suitable for + * the standard line discipline. + */ + clist_alloc_cblocks(&tp->t_canq, TTYHOG, 512); + clist_alloc_cblocks(&tp->t_outq, TTMAXHIWAT + 200, 512); + clist_alloc_cblocks(&tp->t_rawq, TTYHOG, 512); + + return(tp); } -#if 0 /* XXX not yet usable: session leader holds a ref (see kern_exit.c). */ /* - * Free a tty struct. Clists in the struct should have been freed by - * ttyclose(). + * Free a tty structure and its buffers. */ void ttyfree(tp) - struct tty *tp; +struct tty *tp; { - free(tp, M_TTYS); + clist_free_cblocks(&tp->t_canq); + clist_free_cblocks(&tp->t_outq); + clist_free_cblocks(&tp->t_rawq); + FREE(tp, M_TTYS); } -#endif /* 0 */ + diff --git a/sys/kern/tty_snoop.c b/sys/kern/tty_snoop.c index f852a81..eaee544 100644 --- a/sys/kern/tty_snoop.c +++ b/sys/kern/tty_snoop.c @@ -203,6 +203,7 @@ snpin(snp, buf, n) printf("Snoop: more data to down interface.\n"); return 0; } + if (snp->snp_flags & SNOOP_OFLOW) { printf("Snoop: buffer overflow.\n"); /* @@ -212,13 +213,7 @@ snpin(snp, buf, n) * snooping and retry... */ - snp->snp_blen = SNOOP_MINLEN; - free(snp->snp_buf, M_TTYS); - snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); - snp->snp_flags |= SNOOP_DOWN; - snp->snp_flags &= ~SNOOP_OFLOW; - - return (snp_detach(snp)); + return (snpdown(snp)); } s_tail = snp->snp_blen - (snp->snp_len + snp->snp_base); s_free = snp->snp_blen - snp->snp_len; @@ -323,7 +318,7 @@ snp_detach(snp) */ if (snp->snp_unit == -1) - goto destroy_notty; + goto detach_notty; l_tty = &tty_tabs[snp->snp_type]; @@ -338,7 +333,7 @@ snp_detach(snp) snp->snp_unit = -1; -destroy_notty: +detach_notty: selwakeup(&snp->snp_sel); snp->snp_sel.si_pid = 0; @@ -360,7 +355,17 @@ snpclose(dev, flag) return (snp_detach(snp)); } +int +snpdown(snp) + struct snoop *snp; +{ + snp->snp_blen = SNOOP_MINLEN; + free(snp->snp_buf, M_TTYS); + snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); + snp->snp_flags |= SNOOP_DOWN; + return (snp_detach(snp)); +} int @@ -381,6 +386,9 @@ snpioctl(dev, cmd, data, flag) tunit = ((struct snptty *) data)->st_unit; ttype = ((struct snptty *) data)->st_type; + if (ttype == -1 || tunit == -1) + return (snpdown(snp)); + if (ttype < 0 || ttype > ST_MAXTYPE) return (EINVAL); @@ -409,6 +417,11 @@ snpioctl(dev, cmd, data, flag) tp->t_state |= TS_SNOOP; snp->snp_unit = tunit; snp->snp_type = ttype; + /* + * Clean overflow and down flags - + * we'll have a chance to get them in the future :))) + */ + snp->snp_flags &= ~SNOOP_OFLOW; snp->snp_flags &= ~SNOOP_DOWN; splx(s); @@ -434,10 +447,15 @@ snpioctl(dev, cmd, data, flag) s = spltty(); if (snp->snp_unit != -1) *(int *) data = snp->snp_len; - else if (snp->snp_flags & SNOOP_DOWN) - *(int *) data = -1; - else - *(int *) data = 0; + else + if (snp->snp_flags&SNOOP_DOWN) { + if (snp->snp_flags&SNOOP_OFLOW) + *(int *) data = SNP_OFLOW; + else + *(int *) data = SNP_TTYCLOSE; + } else { + *(int *) data = SNP_DETACH; + } splx(s); break; default: |