Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!batcomputer!sun.soe!sun.soe.clarkson.edu!valdis
From: valdis@alchemy.mcs.clarkson.edu (& Kletnieks)
Newsgroups: comp.windows.x
Subject: Re: X11 under SunOS4.0.
Message-ID: 
Date: 20 Sep 88 17:05:28 GMT
References: <24931@bu-cs.BU.EDU> 
Sender: root@sun.soe
Distribution: na
Organization: Clarkson University
Lines: 126
In-reply-to: valdis@alchemy.mcs.clarkson.edu's message of 20 Sep 88 14:29:51 GMT

OK.. Since I've already gotten 2 e-mail msgs asking for the xterm/SunOS 4.0
fix, here it is...  I just fed this to patch, and it worked for me.
Include usual disclaimers - I didn't write the patch, I just use it.

Article 2372 of comp.windows.x
Path: sun.soe.clarkson.edu!batcomputer!cornell!mailrus!ames!oliveb!intelca!mipos3!pinkas
From: pinkas@happy.intel.com (Israel Pinkas ~)
Newsgroups: comp.windows.x
Subject: Re: xterm problems with SunOS 4.0
Message-ID: 
Date: 1 Aug 88 09:09:10 GMT
Sender: nobody@mipos3.intel.com
Distribution: comp
Organization: Corporate CAD, INTeL Corporation, Santa Clara, CA
Lines: 110


bst@alice.uucp (at AT&T Bell Labs, Murray Hill) posted a set of diffs for
xterm that allowed it to run under SunOS 4.0.  Unfortunately, he posted a
diff file that was reversed.  Fortunately, I used patch, which caught this.

Enclosed is a context diff.  This was done after installing bst's patches
on my X10.4 sources.  bst had originally posted the diffs for X11.2, but
they installed in my source offset by ~200 lines without a problem.

To desribe the problem, I run X10.4 on a Sun386i running YP.  When I don't
have a local passwd entry (as we like to do), I would get an error message
from xterm right after clicking with the left button during the create
window.  xterm would bomb out.  The error message was:

	xterm: Error 31, errno 5:

We discovered that this only happend when DISPLAY was set to something
other than unix:0.  According to bst's post (dated 7/21), the error was due
to the YP file descriptor being open.

Anyway, it works for me in X10.4.  It should work with X11.2, but I have no
way of testing it.  I also can't test whether this will break xterm on
anything else.

-Israel Pinkas

----------------------------------------------------------------------
*** main.c.orig	Fri Jun 10 14:55:54 1988
--- main.c	Mon Aug  1 17:20:54 1988
***************
*** 1143,1152 ****
  
  		get_pty (&screen->respond, &tty);
  
! 		if (screen->respond != Xsocket + 1) {
! 			dup2 (screen->respond, Xsocket + 1);
  			close (screen->respond);
! 			screen->respond = Xsocket + 1;
  		}
  
  		/* change ownership of tty to real group and user id */
--- 1143,1152 ----
  
  		get_pty (&screen->respond, &tty);
  
! 		if (screen->respond < 3) {
! 			int newrespond = dupHigh (screen->respond);
  			close (screen->respond);
! 			screen->respond = newrespond;
  		}
  
  		/* change ownership of tty to real group and user id */
***************
*** 1155,1164 ****
  		/* change protection of tty */
  		chmod (ttydev, 0622);
  
! 		if (tty != Xsocket + 2)	{
! 			dup2 (tty, Xsocket + 2);
  			close (tty);
! 			tty = Xsocket + 2;
  		}
  
  		/* set the new terminal's state to be the old one's 
--- 1155,1164 ----
  		/* change protection of tty */
  		chmod (ttydev, 0622);
  
! 		if (tty < 3) {
! 			int newtty = dupHigh (tty);
  			close (tty);
! 			tty = newtty;
  		}
  
  		/* set the new terminal's state to be the old one's 
***************
*** 1531,1533 ****
--- 1531,1553 ----
  	return(ret);
  }
  #endif	opcode
+ 
+ 
+ int dupHigh(oldfd)
+ {
+     int desc[3],i,j;
+     /* Find an fd > 2 */
+     for (i=0;i<3;i++) {
+ 	desc[i] = dup(oldfd);
+ 	if (desc[i] > 2)
+ 	    break;
+ 	}
+     if (i==3) {
+ 	fprintf(stderr,"dupHigh failed\n");
+ 	exit(1);
+ 	}
+     /* Close unneeded ones */
+     for (j=0;j