Subject: openpty fails when used multiple times
To: None <current-users@NetBSD.ORG>
From: Trevor Blackwell <tlb@viaweb.com>
List: current-users
Date: 06/29/1996 11:21:43
Subject: openpty fails when used multiple times

If you call openpty (in libutil) more than once, it hangs.
The problem is that it doesn't restore some static variables, and
tries to open /dev/ttyXX instead of /dev/ptyXX on invocations after
the first.

Here is a fix:

(in /usr/src/lib/libutil)

diff -c pty.c.orig pty.c
*** pty.c.orig  Sat Jun 29 11:15:38 1996
--- pty.c       Sat Jun 29 11:15:07 1996
***************
*** 67,72 ****
--- 67,73 ----
                line[8] = *cp1;
                for (cp2 = "0123456789abcdef"; *cp2; cp2++) {
                        line[9] = *cp2;
+                       line[5] = 'p';
                        if ((master = open(line, O_RDWR, 0)) == -1) {
                                if (errno == ENOENT)
                                        return (-1);    /* out of ptys */
***************
*** 89,95 ****
                                        return (0);
                                }
                                (void) close(master);
-                               line[5] = 'p';
                        }
                }
        }
--- 90,95 ----


 - TLB