[comp.os.xinu] Xinu v6 bug

sdo@CS.PURDUE.EDU (03/31/89)

We just received a bug report from David Schulz:
	David Schulz
	AT&T Bell Laboratories
	att!iexist!schulz

He found a bug in the ttywrite.c routine.  There is an error in that
routine in the V6 code, but not in V7, as the routine is slightly
different there.  The bug is as follows (see added line ==>):

	ttywrite(devptr, buff, count)
	struct	devsw	*devptr;
	char	*buff;
	int	count;
	{
		register struct tty *ttyp;
		int avail;
	
		if (count < 0)
			return(SYSERR);
		if (count == 0)
			return(OK);
		disable();
		ttyp = &tty[devptr->dvminor];
		if ( (avail=scount(ttyp->osem)) >= count) {
			writcopy(buff, ttyp, count);
			sluenable(ttyp);
		} else {
			if (avail > 0) {
				writcopy(buff, ttyp, avail);
				buff += avail;
				count -= avail;
	==>			sluenable(ttyp); /* BUG FIX -- DES */
			}
			for (; count>0 ; count--)
				ttyputc(devptr, *buff++);
		}
		restore();
		return(OK);

This code is for the Sun version, but it also occurs in the original
LSI version with slightly different but obvious syntax.  The routine
sluenable() informs the serial chip that it should interrupt when it
is finished writing characters.  It is disabled when the output buffer
is empty, and re-enabled when it has work to do.  When disabled, the
low level tty routine will not know that it should hand characters to
the chip, and ttywrite() blocks forever.  This bug ONLY occurs when:

1) Output interrupts are disabled, (which implies that the output
   buffer is empty).
2) You call ttywrite() with a buffer size larger than the circular
   output buffer.


Adding the call to sluenable() fixes the problem, and you should
probably patch it in your v6 code.  In non-Sun3 versions of the code,
the new line should be the same as the last line in the "then" portion
of the "if" clause.

If you have problems, please let me know.

Once again, thanks to Mr. Schulz for keeping us all in touch with his
bug fixes.


Shawn

-----------------------------------------------------------------------------
Shawn Ostermann      ARPA:  sdo@cs.purdue.edu      UUCP:  ...!purdue!sdo
-----------------------------------------------------------------------------