[comp.sources.bugs] "Official" patch for screen

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (02/20/89)

I refer to this as an official patch based on this message, which I
recently received:

On Feb 19, 12:38pm, Oliver Laumann wrote:
} Subject: Re: screen
} 
} Thanks for the diffs for screen 2.0.  I didn't have the time
} to reply earlier.
} 
} I don't know if I will ever prepare a new release of screen; I currently
} don't have the time to continue work on screen.  So you might want to post
} a diff for the /dev/tty-bug to comp.sources.bugs.
} 
} Regards,
} --
} Oliver Laumann              net@TUB.BITNET              net@tub.UUCP
} 
}-- End of excerpt from Oliver Laumann

However, this patch may not correspond exactly to the changes made by
Oliver in his own copy -- the patch that I sent to him included several
other aesthetic changes that I have omitted from this posting.

The patch below addresses the following problems:

    *	/dev/tty is opened by every screen process, including slaves and
	"screen -r".  It is used only by the master process.  Opening of
	/dev/tty can safely be moved after the tests for slave functions.

    *	/dev/tty is never closed when screen is detached.  In order for
	the ioctl calls to work correctly, /dev/tty must be closed on
	detach and re-opened on re-attach.

    *	Error returns from the read() system call on descriptor 0 were
	ignored, possibly sending the program into an infinite loop.
	These errors should be detected, and a graceful exit done via
	a call to Finit().

    *	Sequent systems use a different pty naming scheme.  In
	particular, there are no ptyq? or ptyr? devices, and uppercase
	letters are used to provide more ptyp? devices.

Hope this helps some of you other screen fiends out there.  The patch is
for screen.c; you should be able to feed this article directly to patch.

*** /tmp/,RCSt1019085	Sun Feb 19 17:37:46 1989
--- screen.c	Sun Feb 19 17:35:39 1989
***************
*** 263,270 ****
  	*ap = '\0';
      strcat (SockPath, "/");
      SockNamePtr = SockPath + strlen (SockPath);
-     if ((DevTty = open ("/dev/tty", O_RDWR|O_NDELAY)) == -1)
- 	Msg (errno, "/dev/tty");
      if (rflag) {
  	Attach (MSG_ATTACH);
  	Attacher ();
--- 263,268 ----
***************
*** 276,281 ****
--- 274,281 ----
  	close (s);
  	exit (0);
      }
+     if ((DevTty = open ("/dev/tty", O_RDWR|O_NDELAY)) == -1)
+ 	Msg (errno, "/dev/tty");
      switch (fork ()) {
      case -1:
  	Msg (errno, "fork");
***************
*** 350,357 ****
  	    continue;
  	}
  	if (select (32, &r, &w, &x, status ? &tv : (struct timeval *)0) == -1) {
! 	    if (errno == EINTR)
  		continue;
  	    HasWindow = 0;
  	    Msg (errno, "select");
  	    /*NOTREACHED*/
--- 350,359 ----
  	    continue;
  	}
  	if (select (32, &r, &w, &x, status ? &tv : (struct timeval *)0) == -1) {
! 	    if (errno == EINTR) {
! 		errno = 0;
  		continue;
+ 	    }
  	    HasWindow = 0;
  	    Msg (errno, "select");
  	    /*NOTREACHED*/
***************
*** 369,380 ****
  	    if (ESCseen) {
  		inbuf[0] = Esc;
  		inlen = read (0, inbuf+1, IOSIZE-1) + 1;
  		ESCseen = 0;
  	    } else {
  		inlen = read (0, inbuf, IOSIZE);
  	    }
  	    if (inlen > 0)
! 		inlen = ProcessInput (inbuf, inlen);
  	    if (inlen > 0)
  		continue;
  	}
--- 371,391 ----
  	    if (ESCseen) {
  		inbuf[0] = Esc;
  		inlen = read (0, inbuf+1, IOSIZE-1) + 1;
+ 		if (inlen <= 0) {
+ 		    perror("read");
+ 		    Finit();
+ 		}
  		ESCseen = 0;
  	    } else {
  		inlen = read (0, inbuf, IOSIZE);
+ 		if (inlen <= 0) {
+ 		    perror("read");
+ 		    Finit();
+ 		}
  	    }
  	    if (inlen > 0)
! 		if ((inlen = ProcessInput (inbuf, inlen)) < 0)
! 		    Msg(0, "negative ProcessInput return");
  	    if (inlen > 0)
  		continue;
  	}
***************
*** 981,988 ****
--- 992,1004 ----
      strcpy (PtyName, PtyProto);
      strcpy (TtyName, TtyProto);
      for (p = PtyName, i = 0; *p != 'X'; ++p, ++i) ;
+ #ifdef sequent
+     for (l = "p"; *p = *l; ++l) { /*}*/
+ 	for (d = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; p[1] = *d; ++d) { /*}*/
+ #else
      for (l = "qpr"; *p = *l; ++l) {
  	for (d = "0123456789abcdef"; p[1] = *d; ++d) {
+ #endif
  	    if ((f = open (PtyName, O_RDWR)) != -1) {
  		TtyName[i] = p[0];
  		TtyName[i+1] = p[1];
***************
*** 1128,1137 ****
--- 1144,1156 ----
      close (1);
      close (2);
      ioctl (DevTty, TIOCNOTTY, (char *)0);
+     close (DevTty);
      Detached = 1;
      do {
  	ReceiveMsg (ServerSocket); 
      } while (Detached);
+     if ((DevTty = open ("/dev/tty", O_RDWR|O_NDELAY)) == -1)
+ 	Msg (errno, "/dev/tty");
      if (!suspend)
  	for (pp = wtab; pp < wtab+MAXWIN; ++pp)
  	    if (*pp) (*pp)->slot = SetUtmp ((*pp)->tty);
***************
*** 1273,1279 ****
      case MSG_ATTACH:
  	if (Detached) {
  	    if (kill (m.m.attach.apid, 0) == 0 &&
! 		    open (m.m.attach.tty, O_RDWR) == 0) {
  		(void) dup (0);
  		(void) dup (0);
  		AttacherPid = m.m.attach.apid;
--- 1292,1298 ----
      case MSG_ATTACH:
  	if (Detached) {
  	    if (kill (m.m.attach.apid, 0) == 0 &&
! 		    open (m.m.attach.tty, O_RDWR|O_NDELAY) == 0) {
  		(void) dup (0);
  		(void) dup (0);
  		AttacherPid = m.m.attach.apid;

-- 
Bart Schaefer       "Dogs are the animal byproducts in the wienie of life."
                                                                -- Garfield
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sun,tektronix,verdix}!ogccse!schaefer