More changes to support user calls.

It's 22:00  here,utility still to come(hopefully tomorrow
morning..)
This commit is contained in:
ugen 1995-02-15 18:41:57 +00:00
parent 1c49a44459
commit ac4461d616
3 changed files with 91 additions and 60 deletions

View File

@ -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:

View File

@ -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 @@ ttwrite(tp, uio, flag)
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 */

View File

@ -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: