Subject: Re: what's still using pccons ?
To: Bill Studenmund <>
From: Robert Elz <kre@munnari.OZ.AU>
List: tech-kern
Date: 05/11/2001 01:51:53
    Date:        Thu, 10 May 2001 17:29:41 -0700 (PDT)
    From:        Bill Studenmund <>
    Message-ID:  <>

  | On Thu, 10 May 2001, Andrew Brown wrote:
  | > >	a) Modify openpty(3) to skip ttyv. This is the easiest
  | > >	   solution for now, but we lose 16 ptys. I'm going to
  | > >	   commit this for now; we can always revert once one
  | > >	   of the above occurs.
  | > 
  | > #ifdef __i386__ || __prep__ ...
  | > 	use "pqrstuwx..."
  | > #else
  | > 	use "pqrstuvwx..."
  | > #endif
  | > 
  | > ?
  | That would mean that powerpc platfroms couldn't share libutil. We've been
  | working to make ports share as much as they can with other machines of
  | the same architecture.

What's more it is unnecessary.

openpty() is looking for a ptyXn right?   If ttyv0 is something other
than a pty on some port, then there will be no ptyv0 right?

So, all that is needed is to change openpty() so that instead of
stopping when it reaches the first ptyXn that doesn't exist, it
just skip the rest of that particular X, and go on to the next one.
So, when ptyv0 is found to not exist, just go on to ptyw0.

The most this can cost is 15 extra open attempts (ptyp0 will be tried in
every case, if that doesn't exist, we will also trt ttyq0 ttyr0 .. for an
extra 15 attempts).   If someone had a system with a very small number of
ptys that might actually represent a small additional load (after all the
available ptys are used).  In any real case it will be unnoticeable
(no-one ever wants all the available ptys to be in use, in the case that
not all ptys are in use, it costs nothing).

The diff to make this happen is ...

--- pty.c.ORIG	Fri May 11 01:45:39 2001
+++ pty.c	Fri May 11 01:46:06 2001
@@ -87,11 +87,11 @@
 		for (cp2 = "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 */
+					break;		/* on to next letter */
 			} else {
 				line[5] = 't';
 				(void) chown(line, getuid(), ttygid);
 				(void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
 				(void) revoke(line);

Not only does it handle the "who owns ttyv" problem, it also handles
any other conflicts that ever might arise (though they all are handled
by sacrificing 16 ptys - adding an extra letter or two to TTY_LETTERS
would allow ports to make up for any lost due to conflicts).

What's more, it allows people to decide that they don't like ttyq* and
simply delete all of ttyq* and ptyq* and allow ttyr0 to be the next
used after ttypf.   (Yes, I know a benefit worth less than these 3 lines...
and which will break completely once pty cloning is implemented, so just
forget that one!)