summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authoratatat <atatat@NetBSD.org>2002-03-09 20:09:28 +0000
committeratatat <atatat@NetBSD.org>2002-03-09 20:09:28 +0000
commitd76e3cd5fec2dad3d120b97f303a07f83bdee4ef (patch)
tree2f4af966311a20ea2b3d82bea79da446438a4131 /lib/libutil
parentaf646eef115c79dcc7001b4e0883428d4b85a87a (diff)
Fix openpty() so that it correctly scans the entire list of possible
ttys. The new ttys (g-zA-Z) are "optional", since they may not be present, and their absence is not a "fatal" error.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/pty.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c
index 281af9608f2..f918f266fe4 100644
--- a/lib/libutil/pty.c
+++ b/lib/libutil/pty.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pty.c,v 1.18 2002/02/02 05:48:31 tls Exp $ */
+/* $NetBSD: pty.c,v 1.19 2002/03/09 20:09:28 atatat 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.18 2002/02/02 05:48:31 tls Exp $");
+__RCSID("$NetBSD: pty.c,v 1.19 2002/03/09 20:09:28 atatat Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -60,13 +60,15 @@ __RCSID("$NetBSD: pty.c,v 1.18 2002/02/02 05:48:31 tls Exp $");
* XXX: `v' removed until no ports are using console devices which use ttyv0
*/
#define TTY_LETTERS "pqrstuwxyzPQRST"
+#define TTY_OLD_SUFFIX "0123456789abcdef"
+#define TTY_NEW_SUFFIX "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
int
openpty(int *amaster, int *aslave, char *name, struct termios *termp,
struct winsize *winp)
{
static char line[] = "/dev/XtyXX";
- const char *cp1, *cp2;
+ const char *cp1, *cp2, *cp;
int master, slave, tries = 0;
gid_t ttygid;
struct group *gr;
@@ -84,16 +86,16 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
for (cp1 = TTY_LETTERS; *cp1; cp1++) {
tries = 0;
-try:
line[8] = *cp1;
- for (cp2 = !tries ?
- "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" :
- "0123456789abcdef" ; *cp2; cp2++) {
+ for (cp = cp2 = TTY_OLD_SUFFIX TTY_NEW_SUFFIX; *cp2; cp2++) {
line[5] = 'p';
line[9] = *cp2;
if ((master = open(line, O_RDWR, 0)) == -1) {
- if ((errno == ENOENT) && tries) {
- return (-1); /* out of ptys */
+ if (errno == ENOENT) {
+ if (cp2 - cp + 1 < sizeof(TTY_OLD_SUFFIX))
+ return (-1); /* out of ptys */
+ else
+ break;
}
} else {
line[5] = 't';
@@ -115,10 +117,6 @@ try:
}
(void) close(master);
}
- if(!tries) {
- tries++;
- goto try;
- }
}
}
errno = ENOENT; /* out of ptys */