[net.bugs.usg] S3 TTY Driver

jack@rlgvax.UUCP (Jack Waugh) (11/06/83)

         According to rlgvax!jds:

         The System III tty driver uses a coding convention to associate
         flag bits with flag words.  If shown the flag bit "OPOST", you
         immediately know that it pertains to the "t_oflag" flag word of
         the tty structure.  This is just great except that the convention
         is not used 100% of the time.

         The following is the example of what can happen if you come up
         with a nice little coding convention but don't stick to it:

tttimeo(tp)
register struct tty *tp;
{
        tp->t_state &= ~TACT;
        if (tp->t_iflag&ICANON || tp->t_cc[VTIME] == 0)
                return;
        if (tp->t_rawq.c_cc == 0)
                return;
        if (tp->t_state&RTO) {
                tp->t_delct = 1;
                if (tp->t_state&IASLP) {
                        tp->t_state &= ~IASLP;
                        wakeup((caddr_t)&tp->t_rawq);
                }
        } else {
                tp->t_state |= RTO|TACT;
                timeout(tttimeo, tp, tp->t_cc[VTIME]*(HZ/10));
        }
}

         When you see the "ICANON" flag word, you immediately assume (as
         did person who wrote the above function) that it belongs to the
         "t_iflag" word.

         Thus, if you want to check for canonicalization of the input
         stream, you simply do the following:

              if (tp->t_iflag&ICANON)
                   /*
                    * We're processing input characters.
                    */

         Wrong!  The "ICANON" flag is one of those little exceptions -- it
         is a flag bit for "t_lflag".  Thus, the above is equivalent to:

              if (tp->t_iflag&BRKINT)
                   /*
                    * We're processing input characters.
                    */

         Which is not what you want to do at all!

         The upshot of this is that when you do a:

              stty -icanon brkint min '^f' time '^b'

         It isn't going to work like the book tells you it will.

         This is a bug in Bell's S3, meaning it is probably a bug in
         EVERYONE's port of S3.

         It has been fixed in System 5.