Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add support for up to 930 pty devices (instead of the curren...



details:   https://anonhg.NetBSD.org/src/rev/7419df409dff
branches:  trunk
changeset: 521608:7419df409dff
user:      tls <tls%NetBSD.org@localhost>
date:      Sat Feb 02 05:48:30 2002 +0000

description:
Add support for up to 930 pty devices (instead of the current 256).

The openpty() routine has been modified to use the extra pty names
before the "traditional" names, so that programs too dumb to use
openpty() will, hopefully, find one of the "traditional" ptys free
even if many others are in use.  The modifications to MAKEDEV are
courtesy Andrew Brown, and are pretty clever: the unit numbers used
by the "traditional" names stay the same, to avoid trouble when
upgrading existing systems.  The unusual use of "dd" to index an
array in MAKEDEV is because no other simple method seemed feasible
using only the programs on the install media for all ports.

diffstat:

 etc/etc.i386/MAKEDEV |  74 ++++++++++++++++++++++++++-------------------------
 lib/libutil/pty.c    |  21 ++++++++++----
 2 files changed, 53 insertions(+), 42 deletions(-)

diffs (181 lines):

diff -r f47303abd303 -r 7419df409dff etc/etc.i386/MAKEDEV
--- a/etc/etc.i386/MAKEDEV      Sat Feb 02 05:31:56 2002 +0000
+++ b/etc/etc.i386/MAKEDEV      Sat Feb 02 05:48:30 2002 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#      $NetBSD: MAKEDEV,v 1.159 2002/01/21 16:19:21 abs Exp $
+#      $NetBSD: MAKEDEV,v 1.160 2002/02/02 05:48:30 tls Exp $
 #
 # Copyright (c) 1990 The Regents of the University of California.
 # All rights reserved.
@@ -79,7 +79,8 @@
 #              32 ports.
 #
 # Pseudo terminals:
-#      pty*    set of 16 master and slave pseudo terminals
+#      pty*    set of 62 master and slave pseudo terminals
+#      opty    first 16 ptys, to save inodes on install media
 #
 # Printers:
 #      lpt*    stock lp
@@ -164,7 +165,7 @@
 
 all)
        sh $0 std wscons fd wt0 fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3 sd4
-       sh $0 tty0 tty1 tty2 tty3 pty0 pty1 pty2 pty3
+       sh $0 tty0 tty1 tty2 tty3 pty0 pty1
        sh $0 raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
        sh $0 st0 st1 ch0 cd0 cd1 mcd0 vnd0 vnd1 lpa0 lpa1 lpa2
        sh $0 bpf0 bpf1 bpf2 bpf3 bpf4 bpf5 bpf6 bpf7
@@ -206,7 +207,7 @@
 
 floppy)
        sh $0 std wt0 fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3 sd4 tty0 tty1 tty2
-       sh $0 st0 st1 cd0 cd1 mcd0 ttyv0 pty0 ld0 ld1 ld2 ld3 ed0 ed1
+       sh $0 st0 st1 cd0 cd1 mcd0 ttyv0 opty ld0 ld1 ld2 ld3 ed0 ed1
        ;;
 
 ramdisk)
@@ -572,48 +573,49 @@
        chown uucp.wheel tty$unit dty$unit
        ;;
 
+opty)
+       rm -f ttyp[0-9a-f] ptyp[0-9a-f]
+       for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
+       do
+               case $j in
+               [0-9])  jn=$j ;;
+               a)      jn=10 ;;
+               b)      jn=11 ;;
+               c)      jn=12 ;;
+               d)      jn=13 ;;
+               e)      jn=14 ;;
+               f)      jn=15 ;;
+               esac
+               mknod ttyp$j c 5 $jn
+               mknod ptyp$j c 5 $jn
+       done
+               
 pty*)
        class=${i#pty}
-       case $class in
-       0)      name=p;;
-       1)      name=q;;
-       2)      name=r;;
-       3)      name=s;;
-       4)      name=t;;
-       5)      name=u;;
-       6)      name=v
-               echo "$0: $i: pty unit conflicts with console ttyv0 device."
+       name=`echo pqrstuvwxyzPQRST | dd bs=1 count=1 skip=$class 2>/dev/null`
+       case $name in
+       v)      echo "$0: $i: pty unit conflicts with console ttyv0 device."
                continue;;
-       7)      name=w;;
-       8)      name=x;;
-       9)      name=y;;
-       10)     name=z;;
-       11)     name=P;;
-       12)     name=Q;;
-       13)     name=R;;
-       14)     name=S;;
-       15)     name=T;;
+       ?)      ;;
        *)      echo "$0: $i: pty unit must be between 0 and 15"
                continue ;;
        esac
-       rm -f tty$name[0-9a-f] pty$name[0-9a-f]
-       for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
+       rm -f tty$name[0-9a-zA-Z] pty$name[0-9a-zA-Z]
+       jn=0
+       while [ $jn -lt 62 ]
        do
-               case $j in
-               [0-9])  jn=$j ;;
-               a)      jn=10 ;;
-               b)      jn=11 ;;
-               c)      jn=12 ;;
-               d)      jn=13 ;;
-               e)      jn=14 ;;
-               f)      jn=15 ;;
-               esac
-               unit=$(($class * 16 + $jn))
+               j=`echo 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ | dd bs=1 count=1 skip=$jn 2>/dev/null`
+               skip=0
+               if [ $jn -ge 16 ]; then
+                       skip=$(($class * 30 + 256 - 16))
+               fi
+               unit=$(($class * 62 + $jn + $skip))
                mknod tty$name$j c 5 $unit
                mknod pty$name$j c 6 $unit
+               jn=$(($jn + 1))
        done
-        chgrp wheel tty$name? pty$name?
-        chmod 666 tty$name? pty$name?
+        chgrp wheel tty$name[0-9a-zA-Z] pty$name[0-9a-zA-Z]
+        chmod 666 tty$name[0-9a-zA-Z] pty$name[0-9a-zA-Z]
        ;;
 
 st*)
diff -r f47303abd303 -r 7419df409dff lib/libutil/pty.c
--- a/lib/libutil/pty.c Sat Feb 02 05:31:56 2002 +0000
+++ b/lib/libutil/pty.c Sat Feb 02 05:48:30 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pty.c,v 1.17 2001/05/10 01:57:47 lukem Exp $   */
+/*     $NetBSD: pty.c,v 1.18 2002/02/02 05:48:31 tls Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)pty.c      8.3 (Berkeley) 5/16/94";
 #else
-__RCSID("$NetBSD: pty.c,v 1.17 2001/05/10 01:57:47 lukem Exp $");
+__RCSID("$NetBSD: pty.c,v 1.18 2002/02/02 05:48:31 tls Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -67,7 +67,7 @@
 {
        static char line[] = "/dev/XtyXX";
        const char *cp1, *cp2;
-       int master, slave;
+       int master, slave, tries = 0;
        gid_t ttygid;
        struct group *gr;
 
@@ -83,13 +83,18 @@
                ttygid = (gid_t) -1;
 
        for (cp1 = TTY_LETTERS; *cp1; cp1++) {
+               tries = 0;
+try:
                line[8] = *cp1;
-               for (cp2 = "0123456789abcdef"; *cp2; cp2++) {
+               for (cp2 = !tries ?
+                    "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" :
+                    "0123456789abcdef" ; *cp2; cp2++) {
                        line[5] = 'p';
                        line[9] = *cp2;
                        if ((master = open(line, O_RDWR, 0)) == -1) {
-                               if (errno == ENOENT)
-                                       return (-1);    /* out of ptys */
+                               if ((errno == ENOENT) && tries) {
+                                       return (-1);    /* out of ptys */
+                               }
                        } else {
                                line[5] = 't';
                                (void) chown(line, getuid(), ttygid);
@@ -110,6 +115,10 @@
                                }
                                (void) close(master);
                        }
+                       if(!tries) {
+                               tries++;
+                               goto try;
+                       }
                }
        }
        errno = ENOENT; /* out of ptys */



Home | Main Index | Thread Index | Old Index