Subject: 9term bug

From: [email-masked]
Date: Thu, 1 Dec 1994 19:09:33 -0500

Has anybody else seen this race in 9term?  Here's an excerpt from
sendrunes:

        if (p > s)
                while (write(comm_fd, s, p-s) < 0 && errno == EAGAIN)
                                ;
                /* reinstate echo mode, if we disabled it above */
        if (echo) {
                ttmode.c_lflag |= ECHO;
                IOSETATTR(slave_fd, &ttmode);
        }

The IOSETATTR can race with the line discipline's processing of
characters written on comm_fd.  When the IOSETATTR beats the input
processing, some suffix of the input is echoed an extra time.

I've seen this only on some multiprocessors, but it seems theoretically
possible in other settings.  My workaround is nondeterministic, but it
works on the hosts where I've tried it.

        if (echo) {
		tcdrain(comm_fd);
                ttmode.c_lflag |= ECHO;
                IOSETATTR(slave_fd, &ttmode);
        }

Anybody got a better way to handle this?

--Mike Scheer, 908-273-1885, [email-masked]