[comp.windows.x] problems with X.V11R3 xterm under SunOS

raj@GLACIER.ICS.UCI.EDU (11/09/88)

Sorry, I found that someone else here had patched our version of xterm in order
to fix another problem and the patch caused my new problem!  Let me explain
the situation:

If you start an xterm on a system and then run a program which produces output
forever (like:
	#!/bin/csh -f
	while (1)
		echo hello
	end
for example) you'll see that whenever someone happens to get that same pty
they will get your output!  We solved this under R2 by putting in a vhangup()
right after the "chmod(something, 0666)" in main.c (there's only one).
Putting in this same vhangup at the same place in R3 causes the problem I
reported before.  The actual solution is this:

1) you have to throw away your controlling terminal in the parent.
2) you have to open the ttyp? side of the pty in get_pty so as to set the
   controlling terminal correctly so that...
3) you can now put in the vhangup in the place mentioned above and it will
   work correctly with no bad side-effects.

Here are the diffs (you line numbers will definitely vary, we've made other
fixes than this):

*** bk_main.c	Wed Nov  2 12:23:39 1988
--- main.c	Tue Nov  8 16:33:41 1988
***************
*** 946,951 ****
--- 947,954 ----
  	/* got one! */
  	return(0);
  #else /* not (mips && SYSTYPE_SYSV) */
+ 	int	tty;
+ 
  	while (PTYCHAR1[letter]) {
  	    ttydev [strlen(ttydev) - 2]  = ptydev [strlen(ptydev) - 2] =
  		    PTYCHAR1 [letter];
***************
*** 958,963 ****
--- 961,973 ----
  			 * into this function!
  			 */
  			(void) devindex++;
+ 			/*
+ 			 * Set the corresponding ttyp? as our controlling
+ 			 * terminal so that the vhangup later will work
+ 			 */
+ 			if((tty = open(ttydev, O_RDWR)) >= 0) {
+ 				close(tty);
+ 			}
  			return(0);
  		}
  		devindex++;
***************
*** 1218,1223 ****
--- 1228,1239 ----
  				SysError (ERROR_TIOCLGET);
  #endif	/* USE_SYSV_TERMIO */
  			close (tty);
+ #ifdef TIOCNOTTY	/* throw away our controlling terminal */
+ 			if ((tty = open("/dev/tty", 2)) >= 0) {
+ 				ioctl(tty, TIOCNOTTY, (char *)NULL);
+ 				close(tty);
+ 			}
+ #endif	TIOCNOTTY
  			/* tty is no longer an open fd! */
  			tty = -1;
  		}
***************
*** 2033,2038 ****
--- 2062,2069 ----
  
  		/* restore modes of tty */
  		chmod (ttydev, 0666);
+ /* Make sure all other processes on this pesudo-tty can't continue to write */
+ 		vhangup();
  	}
  	exit(n);
  }

-----------------------------------------------------------------------------
Richard A. Johnson                               raj@ics.uci.edu   (Internet)
UCI ICS Assistant Support Manager                  ucbvax!ucivax!raj   (UUCP)
Postmaster / Network Services       raj@tertius.ics.uci.edu (via Nameservers)