[comp.os.minix] fix for bug in serial driver

bob@dhw68k.cts.com (Bob Best) (10/30/88)

I was having serious problems with the serial driver when separate processes
were attempting to write simultaneously on /dev/tty1.  For example, the
following shell command was certain to crash:
	dis88 foo | less
The problem was that dis88 was sending an error message to stderr regarding
symbols not found at the same time that less was attempting to output
on stdout.  I examined the code for do_write() in tty.c and it seemed
that Andy had provided security against just this type of multi-access.
Some debugging code finally provided the evidence that testing tp->tty_outleft
greater than zero was insufficient.  I replaced this line with:

   if (tp->tty_waiting) {	/* if someone else is hanging, give up */

Now everything runs smoothly.

There are also some problems when a program that continuously scrolls
output is running simultaneously on /dev/tty0 and /dev/tty1.  I am not
overly concerned about this, since the system would rarely operate this
way.  However, for the record, when running simultaneously on /dev/tty0
and /dev/tty1, the following program will display about 20 lines and
then stop for about 8 seconds on /dev/tty1 while scrolling nonstop on
/dev/tty0.  This is probably not a bug, but a consequence of the console
output routines somehow taking precedence over the rs232 output routines.
--------------begin nonstop.c-------
/* nonstop.c - test program to continuously scroll output
 * Hit DEL to kill
 */
main()
{
	int i=0;

	while(1)
		printf("This is number %d\n",++i);
}
------------end nonstop.c----------

This is the patch for kernel/tty.c to fix the bug described above:
Index: tty.c
*** tty.c~	Sat Oct 29 13:18:25 1988
--- tty.c	Sat Oct 29 13:20:18 1988
***************
*** 580,586 ****
    int caller,replyee;
  
    /* If the slot is already in use, better return an error than mess it up. */
!   if (tp->tty_outleft > 0) {	/* if someone else is hanging, give up */
  	tty_reply(TASK_REPLY, m_ptr->m_source, m_ptr->PROC_NR, EIO, 0L, 0L);
  	return;
    }
--- 580,586 ----
    int caller,replyee;
  
    /* If the slot is already in use, better return an error than mess it up. */
!   if (tp->tty_waiting) {	/* if someone else is hanging, give up */
  	tty_reply(TASK_REPLY, m_ptr->m_source, m_ptr->PROC_NR, EIO, 0L, 0L);
  	return;
    }
-- 
Bob Best
uucp: ...{trwrb,hplabs}!felix!dhw68k!bob	InterNet: bob@dhw68k.cts.com