Subject: Re: Strange console output
To: None <current-users@netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: current-users
Date: 02/01/2004 01:13:49
--BwCQnh7xodEAoBMC
Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp"
Content-Disposition: inline


--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hernani Marques Madeira wrote:
> The ttyp* are set to network what's the reason why the last snip above
> has as TERM networ (where's the terminating k? :)

This is a bug in getttyent() - thus also in getttyname(). The attached patch
should fix this problem and a couple of others.

--=20
Christian

--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="getttyent.c.udif"
Content-Transfer-Encoding: quoted-printable

Index: lib/libc/gen/getttyent.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
RCS file: /cvsroot/src/lib/libc/gen/getttyent.c,v
retrieving revision 1.20
diff -u -r1.20 getttyent.c
--- lib/libc/gen/getttyent.c	2003/08/07 16:42:51	1.20
+++ lib/libc/gen/getttyent.c	2004/02/01 00:08:39
@@ -56,7 +56,7 @@
 __weak_alias(setttyent,_setttyent)
 #endif
=20
-static char zapchar;
+static char *comment;
 static FILE *tf;
 static size_t lineno =3D 0;
 static char *skip __P((char *));
@@ -93,12 +93,13 @@
 		free(line);
 	for (;;) {
 		errno =3D 0;
-		line =3D fparseln(tf, &len, &lineno, NULL, FPARSELN_UNESCALL);
+		line =3D fparseln(tf, &len, &lineno, "\\\\\0", FPARSELN_UNESCALL);
 		if (line =3D=3D NULL) {
 			if (errno !=3D 0)
 				warn("gettyent");
 			return NULL;
 		}
+	=09
 		for (p =3D line; *p && isspace((unsigned char) *p); p++)
 			continue;
 		if (*p && *p !=3D '#')
@@ -106,9 +107,10 @@
 		free(line);
 	}
=20
-	zapchar =3D 0;
+	comment =3D NULL;
 	tty.ty_name =3D p;
 	p =3D skip(p);
+
 	if (!*(tty.ty_getty =3D p))
 		tty.ty_getty =3D tty.ty_type =3D NULL;
 	else {
@@ -120,6 +122,7 @@
 	}
 	tty.ty_status =3D 0;
 	tty.ty_window =3D NULL;
+	tty.ty_class =3D NULL;
=20
 #define	scmp(e)	!strncmp(p, e, sizeof(e) - 1) && (isspace((unsigned char) =
p[sizeof(e) - 1]) || p[sizeof(e) - 1] =3D=3D '\0')
 #define	vcmp(e)	!strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] =3D=3D '=
=3D'
@@ -148,13 +151,11 @@
 			warnx("gettyent: %s, %lu: unknown option `%s'",
 			    _PATH_TTYS, (unsigned long)lineno, p);
 	}
+
+	if (comment || (comment =3D strchr(p, '#')))
+		p =3D comment;
=20
-	if (zapchar =3D=3D '#' || *p =3D=3D '#')
-		while ((c =3D *++p) =3D=3D ' ' || c =3D=3D '\t')
-			;
-	tty.ty_comment =3D p;
-	if (*p =3D=3D 0)
-		tty.ty_comment =3D 0;
+	tty.ty_comment =3D *p ? p : NULL;
 	if ((p =3D strchr(p, '\n')) !=3D NULL)
 		*p =3D '\0';
 	return (&tty);
@@ -167,15 +168,15 @@
  * the next field.
  */
 static char *
-skip(p)
-	char *p;
+skip(s)
+	char *s;
 {
-	char *t;
+	char *t, *p;
 	int c, q;
=20
 	_DIAGASSERT(p !=3D NULL);
=20
-	for (q =3D 0, t =3D p; (c =3D *p) !=3D '\0'; p++) {
+	for (q =3D 0, t =3D p =3D s; (c =3D (u_char)*p) !=3D '\0'; p++) {
 		if (c =3D=3D '"') {
 			q ^=3D QUOTED;	/* obscure, but nice */
 			continue;
@@ -186,19 +187,26 @@
 		if (q =3D=3D QUOTED)
 			continue;
 		if (c =3D=3D '#') {
-			zapchar =3D c;
-			*p =3D 0;
+			*p =3D '\0';
+			comment =3D p + 1;
 			break;
 		}
-		if (c =3D=3D '\t' || c =3D=3D ' ' || c =3D=3D '\n') {
-			zapchar =3D c;
+		if (isspace(c)) {
 			*p++ =3D 0;
-			while ((c =3D *p) =3D=3D '\t' || c =3D=3D ' ' || c =3D=3D '\n')
+			while (isspace((u_char)*p))
 				p++;
+			if (*p =3D=3D '#') {
+				*p++ =3D '\0';
+				while (isspace((u_char)*p))
+					p++;
+				comment =3D p;
+				p =3D strchr(p, '\0');
+			}
 			break;
 		}
 	}
-	*--t =3D '\0';
+	if (t > s && c !=3D '\0')
+		*--t =3D '\0';
 	return (p);
 }
=20

--LQksG6bCIzRHxTLp--

--BwCQnh7xodEAoBMC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (NetBSD)

iD8DBQFAHES90KQix3oyIMcRAgLnAJ0U1R0pkCIeiigFBsqzsFeIdKaaWACeO0gP
5RxFkhRvboHay43fXghewXE=
=Nl0N
-----END PGP SIGNATURE-----

--BwCQnh7xodEAoBMC--