[gnu.emacs.bug] opening pty's

sarantos@notecnirp.Princeton.EDU (Sarantos Kapidakis) (07/21/89)

Here is a fix for the file process.c on the gnu emacs distribution
18.54. It eliminates the error message "Opening pty", and continues
looking for the next available pty, when that error would happen.

I should mention here that the bug was not on the emacs code, but on
our system (BSD4.3), that sometimes thinks that a pty is available,
when it really is not (normally that error should never occur).

Anyway, here are the changes. I hope they are incorporated on the next
emacs distribution, since the problem is not only ours, so that they
need not be applied locally. Users that never had the error message
"Opening pty", need not apply the changes to their copy now.


*** process.c.orig	Tue Jul 18 18:35:18 1989
--- process.c	Wed Jul 12 13:26:39 1989
***************
*** 222,230 ****
  
  char ptyname[24];
  
  char *
! pty (ptyv)
!      int *ptyv;
  {
    struct stat stb;
    register c, i;
--- 222,238 ----
  
  char ptyname[24];
  
+ /* Return a pty only if both the pty and tty can be opened for RDWR.
+    The previous code returned a pty that could be opened with RDWR,
+    and then it was producing an error if the tty could not be opened
+    for RDWR.   Since this was happening in our system (4.3BSD), this
+    fix overcomes that inconvenience.
+    Anyway, the code is more structured now, since both descriptors
+    are opened and returned together */
+ 
  char *
! pty (ptyv, ttyv)
!      int *ptyv, *ttyv;
  {
    struct stat stb;
    register c, i;
***************
*** 285,291 ****
--- 293,306 ----
  #endif /* not HPUX */
  #endif /* no PTY_TTY_NAME_SPRINTF */
  #ifndef UNIPLUS
+ #ifndef USG
+       /* On USG systems it does not work to open
+ 	 the pty's tty here and then close and reopen it in the child.  */
+ 	    if ((*ttyv = open (ptyname, O_RDWR, 0)) < 0)
+ #else
+ 	    *ttyv = -1;
  	    if (access (ptyname, 6) != 0)
+ #endif
  	      {
  		close (*ptyv);
  #ifndef IRIS
***************
*** 914,935 ****
  
  #ifdef HAVE_PTYS
    if (EQ (Vprocess_connection_type, Qt))
!     ptyname = pty (&inchannel);
  
    outchannel = inchannel;
!   if (ptyname)
!     {
! #ifndef USG
!       /* On USG systems it does not work to open
! 	 the pty's tty here and then close and reopen it in the child.  */
!       forkout = forkin = open (ptyname, O_RDWR, 0);
!       if (forkin < 0)
! 	report_file_error ("Opening pty", Qnil);
! #else
!       forkin = forkout = -1;
! #endif
!     }
!   else
  #endif /* HAVE_PTYS */
  #ifdef SKTPAIR
      {
--- 929,939 ----
  
  #ifdef HAVE_PTYS
    if (EQ (Vprocess_connection_type, Qt))
!     ptyname = pty (&inchannel, &forkin);
  
    outchannel = inchannel;
!   forkout = forkin;
!   if (!ptyname)
  #endif /* HAVE_PTYS */
  #ifdef SKTPAIR
      {