[comp.bugs.sys5] termio TCSETAF bug

mb@ttidca.TTI.COM (Michael Bloom) (09/10/88)

The man page for TERMIO(7) states that TCSETAF flushes the input queue
after waiting for output to drain.

In fact, in s5 rel 3.0, it's doing a ttyflush(tp,FREAD|FWRITE), flushing
both input AND output.

Harmless, you say, since it's already waited for output to drain? 

Not so.  I discovered this after adding packet mode to the pty driver
on my system to support remote flushing. Afterward, the bug displayed
itself quite graphically. While rlogined, every time emacs called it's
internal error handler, i.e to report an invalid command, the screen
would go haywire.

This turned out to be due to emacs's use of TCSETAF to flush terminal
input on user error.  The flush (both input and OUTPUT) was being
propagated out of band to the rlogin client, which dutifully flushed
output smack in the middle of a set of terminal escape sequences which
were only now being displayed.

Admittedly, TCFLSH would have been a better choice for emacs to have used,
but given the current termio documentation, the use of TCSETAF was not
unreasonable. For the time being, i've modified emacs to use TCFLSH.

So, now two questions.

First, is this a bug in the documentation or in the tty code?

Second, noting that the SunOs 4.0 manual page is identical in this
regard to the sys5 manual page, does TCSETAF behavior in the new Sun
tty driver follow the man page or the original sys5 code?

guy@gorodish.Sun.COM (Guy Harris) (09/13/88)

> First, is this a bug in the documentation or in the tty code?

I would consider it a bug in the tty code; the author probably thought it was
OK to include output, since it had obviously made it all out to the terminal,
and didn't consider something such as pseudo-ttys or "rlogin" (which didn't
exist in S5R3).

> Second, noting that the SunOs 4.0 manual page is identical in this
> regard to the sys5 manual page, does TCSETAF behavior in the new Sun
> tty driver follow the man page or the original sys5 code?

The man page.  None of the original S5 code was used in the 4.0 driver, since
the 4.0 tty subsystem is streams-based....

perry@hpfcdc.HP.COM (Perry Scott) (09/16/88)

>In fact, in s5 rel 3.0, it's doing a ttyflush(tp,FREAD|FWRITE), flushing
>both input AND output.

We decided this was a bug in the code.  (Berkeley application)
Importability is difficult with the AT&T behavior.  Backward
compatibility should not be a problem because the output queue
should already be empty on "real" tty devices.

Perry Scott
Hewlett-Packard