[comp.windows.x] R4 xterm bug?

ary@mentor.cc.purdue.edu (Bryan "Archer" Rowland) (02/24/90)

We believe we have found a bug in X11R4 xterm.  The problem appears
when you log in from a Visual X19 Display Station via a telnet
connection, start your X clients, and log out of the telnet window.
Most users begin their X sessions by typing "startx; kill -9 $$" (or
their own shell script that replaces startx) from their telnet window.

What happens is that the X11R4 xterm attempts to open /dev/tty in order
to perform a TIOCNOTTY.  However, by the time this open is attempted,
the user has logged out of the terminal starting the xterm, so the open
on /dev/tty hangs.  This is apparently a known problem, given this bit
of code from xterm/main.c:

	/*
	 * Sometimes /dev/tty hangs on open (as in the case of a pty
	 * that has gone away).  Simply make up some reasonable
	 * defaults.
	 */
	signal(SIGALRM, hungtty);
	alarm(2);		/* alarm(1) might return too soon */
	if (! setjmp(env)) {
		tty = open ("/dev/tty", O_RDWR, 0);
		alarm(0);
	} else {
		tty_got_hung = True;
		tty = -1;
		errno = ENXIO;
	}

This alarm fixes the case of this open failing, but later on xterm
just does:

	if ((tty = open ("/dev/tty", 2)) >= 0) {
		ioctl (tty, TIOCNOTTY, (char *) NULL);
		close (tty);
	}

, not taking into account that a similar open hung earlier.

To avoid this, the only solution that we have found is to skip this
open/TIOCNOTTY if the earlier open on /dev/tty hung.  The fix was
simple, since the variable no_dev_tty is set to 1 when there is a hung
tty.  I have included a context diff of main.c showing the change.
This leaves the xterm associated with the tty, of course.

Since we would prefer to disassociate the xterm from the tty (like what
was done in the X11R3 xterm), we hope someone can find a proper fix for
this bug.  Has anyone else had this problem?  How was it solved?

	thanx,
	Bryan

*** ./main.c	Thu Feb 22 22:19:28 1990
--- /usr/xwindows/X11R4/mit/clients/xterm/main.c	Thu Feb 22 01:51:06 1990
***************
*** 1439,1445 ****
  #endif	/* USE_SYSV_PGRP */
  		while (1) {
  #ifdef TIOCNOTTY
! 			if ((tty = open ("/dev/tty", 2)) >= 0) {
  				ioctl (tty, TIOCNOTTY, (char *) NULL);
  				close (tty);
  			}
--- 1439,1445 ----
  #endif	/* USE_SYSV_PGRP */
  		while (1) {
  #ifdef TIOCNOTTY
! 			if (!no_dev_tty && (tty = open ("/dev/tty", 2)) >= 0) {
  				ioctl (tty, TIOCNOTTY, (char *) NULL);
  				close (tty);
  			}

--
Bryan Rowland		Purdue University Computing Center
The Archer		UNIX Systems Programmer
>>>------>		<ary@mentor.cc.purdue.edu>