Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Sep 2008 19:21:49 +0200
From:      Ed Schouten <ed@80386.nl>
To:        Claude Buisson <clbuisson@orange.fr>
Cc:        FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: Problem telneting to a new -current
Message-ID:  <20080923172149.GN81522@hoeg.nl>
In-Reply-To: <48D81DEE.4070103@orange.fr>
References:  <48D81DEE.4070103@orange.fr>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <ed@80386.nl>
 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080923172149.GN81522>