From owner-freebsd-current@FreeBSD.ORG Tue Sep 23 17:21:50 2008 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F283E106568F for ; Tue, 23 Sep 2008 17:21:50 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from palm.hoeg.nl (mx0.hoeg.nl [IPv6:2001:7b8:3fb::211]) by mx1.freebsd.org (Postfix) with ESMTP id D47E78FC1B for ; Tue, 23 Sep 2008 17:21:49 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: by palm.hoeg.nl (Postfix, from userid 1000) id 447121CC46; Tue, 23 Sep 2008 19:21:49 +0200 (CEST) Date: Tue, 23 Sep 2008 19:21:49 +0200 From: Ed Schouten To: Claude Buisson Message-ID: <20080923172149.GN81522@hoeg.nl> References: <48D81DEE.4070103@orange.fr> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xrUWgNVErK0vNKPg" Content-Disposition: inline In-Reply-To: <48D81DEE.4070103@orange.fr> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: FreeBSD Current Subject: Re: Problem telneting to a new -current X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Sep 2008 17:21:51 -0000 --xrUWgNVErK0vNKPg Content-Type: multipart/mixed; boundary="eUGqGfkt69yEwRle" Content-Disposition: inline --eUGqGfkt69yEwRle Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Claude, Sorry for letting you wait this long. I was in a rush this afternoon, so I couldn't fix it for you right away. It turns out there was a small inconsistency between the old and the new pseudo-terminal driver, which caused telnetd to exit prematurely. The new pts(4) driver did not track any state on if it had been used already. This meant that when select() in telnetd would be called right before the child processes had opened the TTY device node, it would just assume that the session was already finished. I've committed a fix to SVN (183308), which should removes this inconsistency. I assumed it wouldn't be a very important problem, because most of the PTY consumers already use the openpty() routine, which already opens the TTY device node unconditionally. It turns out some things went bad after all. Could you try updating to the latest sources to see if the problem is solved now? I've also spotted another `bug' in telnetd. If I log in to telnetd, I see the following message appear in dmesg: pid 2362 (telnetd) is using legacy pty devices This means telnetd has its own PTY allocation routines, instead of using posix_openpt(2) or openpty(3). I've attached a patch that converts telnetd to openpty(3). I'll see if I can get this patch or something similar integrated. Thanks for reporting the issue! --=20 Ed Schouten WWW: http://80386.nl/ --eUGqGfkt69yEwRle Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="telnetd.diff" Content-Transfer-Encoding: quoted-printable Index: contrib/telnet/telnetd/sys_term.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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; =20 - (void) strcpy(line, _PATH_DEV); - (void) strcat(line, "ptyXX"); - p1 =3D &line[8]; - p2 =3D &line[9]; - - for (cp =3D "pqrsPQRS"; *cp; cp++) { - struct stat stb; - - *p1 =3D *cp; - *p2 =3D '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 =3D 0; i < 32; i++) { - *p2 =3D alpha[i]; - p =3D open(line, 2); - if (p > 0) { - line[5] =3D 't'; - chown(line, 0, 0); - chmod(line, 0600); - return(p); - } - } - } - return(-1); + if (openpty(&p, &s, line, NULL, NULL) =3D=3D -1) + return (-1); +=09 + /* + * Leave the slave device node open. If we close it, a race + * condition could occur between select() in telnetd and + * spawning the child processes. + */ +=09 + return (p); } =20 #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 } =20 Index: libexec/telnetd/Makefile =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libexec/telnetd/Makefile (revision 183273) +++ libexec/telnetd/Makefile (working copy) @@ -17,7 +17,8 @@ WARNS?=3D 2 WFORMAT?=3D 0 =20 -CFLAGS+=3D -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON -DENV_HACK +CFLAGS+=3D -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON \ + -DENV_HACK -DSTREAMSPTY =20 .if ${MK_INET6_SUPPORT} !=3D "no" CFLAGS+=3D -DINET6 --eUGqGfkt69yEwRle-- --xrUWgNVErK0vNKPg Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkjZJa0ACgkQ52SDGA2eCwWvkQCfUvRK3BlfM2aU2mpJwWorL/zE FqYAniyL9MSfSM8NhQHHeyA5CLvVkjTD =g4Je -----END PGP SIGNATURE----- --xrUWgNVErK0vNKPg--