Makes sense to me, ok nicm
On Mon, Dec 03, 2012 at 11:38:49PM +0100, Mark Kettenis wrote: > So the code doesn't check for EOF, and even has a nice fat XXX for it. > This has some nasty consequences. If you ssh into a machine, run > cu(1), and then break the connection, cu(1) start sending the '-1' > character down the serial line like crazy. This is especially bad > since it seems our tty subsystem hangs on closing a tty if it has any > characters in its output buffer. This diff adds the necessary EOF > checks and calls cleanup(0) if it detects one, which will terminate > the process. > > ok? > > > Index: tip.c > =================================================================== > RCS file: /cvs/src/usr.bin/tip/tip.c,v > retrieving revision 1.53 > diff -u -p -r1.53 tip.c > --- tip.c 3 Jul 2010 03:33:12 -0000 1.53 > +++ tip.c 3 Dec 2012 22:28:39 -0000 > @@ -296,8 +296,10 @@ tipin(void) > } > > while (1) { > - gch = getchar()&STRIP_PAR; > - /* XXX does not check for EOF */ > + gch = getchar(); > + if (gch == EOF) > + cleanup(0); > + gch &= STRIP_PAR; > if (gch == vgetnum(ESCAPE) && bol) { > if (!noesc) { > if (!(gch = escape())) > @@ -313,8 +315,12 @@ tipin(void) > if (vgetnum(HALFDUPLEX)) > printf("\r\n"); > continue; > - } else if (!cumode && gch == vgetnum(FORCE)) > - gch = getchar() & STRIP_PAR; > + } else if (!cumode && gch == vgetnum(FORCE)) { > + gch = getchar(); > + if (gch == EOF) > + cleanup(0); > + gch &= STRIP_PAR; > + } > bol = any(gch, vgetstr(EOL)); > if (vgetnum(RAISE) && islower(gch)) > gch = toupper(gch); > @@ -338,8 +344,10 @@ escape(void) > esctable_t *p; > char c = vgetnum(ESCAPE); > > - gch = (getchar()&STRIP_PAR); > - /* XXX does not check for EOF */ > + gch = getchar(); > + if (gch == EOF) > + cleanup(0); > + gch &= STRIP_PAR; > for (p = etable; p->e_char; p++) > if (p->e_char == gch) { > printf("%s", ctrl(c));