Index: contrib/telnet/telnetd/sys_term.c =================================================================== --- contrib/telnet/telnetd/sys_term.c (revision 183273) +++ contrib/telnet/telnetd/sys_term.c (working copy) @@ -398,40 +398,18 @@ int getpty(int *ptynum __unused) { - int p; - const char *cp; - char *p1, *p2; - int i; + int p, s; - (void) strcpy(line, _PATH_DEV); - (void) strcat(line, "ptyXX"); - p1 = &line[8]; - p2 = &line[9]; - - for (cp = "pqrsPQRS"; *cp; cp++) { - struct stat stb; - - *p1 = *cp; - *p2 = '0'; - /* - * This stat() check is just to keep us from - * looping through all 256 combinations if there - * aren't that many ptys available. - */ - if (stat(line, &stb) < 0) - break; - for (i = 0; i < 32; i++) { - *p2 = alpha[i]; - p = open(line, 2); - if (p > 0) { - line[5] = 't'; - chown(line, 0, 0); - chmod(line, 0600); - return(p); - } - } - } - return(-1); + if (openpty(&p, &s, line, NULL, NULL) == -1) + return (-1); + + /* + * Leave the slave device node open. If we close it, a race + * condition could occur between select() in telnetd and + * spawning the child processes. + */ + + return (p); } #ifdef LINEMODE @@ -463,7 +441,11 @@ #ifndef USE_TERMIO return(termbuf.state & TS_EXTPROC); #else +# ifdef EXTPROC return(termbuf.c_lflag & EXTPROC); +# else /* !EXTPROC */ + return(0); +#endif /* EXTPROC */ #endif } Index: libexec/telnetd/Makefile =================================================================== --- libexec/telnetd/Makefile (revision 183273) +++ libexec/telnetd/Makefile (working copy) @@ -17,7 +17,8 @@ WARNS?= 2 WFORMAT?= 0 -CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON -DENV_HACK +CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON \ + -DENV_HACK -DSTREAMSPTY .if ${MK_INET6_SUPPORT} != "no" CFLAGS+= -DINET6