Hello David,

changes for user/telnetd:

 - add Unix98 pty support through openpty() when uClibc is being used.
   Now telnetd works fine with devfs and devpts ;-)

 - kill unreachable usage() function (options parsing was commented out);

 - remove BSD rcsid crap (save about 1KB in .data section);

With openpty(), telnetd size was reduced from 38120 to 36412. With some
additional effort it should be possible to bring telnetd below 32768 for
a big improvement with the crappy 2's power page_alloc.

WARNING: there is a bug hiding somewhere in telnetd. If uClibc is built with
UCLIBC_HAS_WCHAR, telnetd sends "InvInvInvInv" to the remote client
after spawning login. After some long debug hours, I found out that
"Inv" is the beginning of the message "Invalid multibyte format string.",
contained in uClibc. It happens with or without this patch applied.


diff -u -r1.1.1.3 Makefile
--- user/telnetd/Makefile	16 May 2003 01:13:08 -0000	1.1.1.3
+++ user/telnetd/Makefile	19 Jul 2003 17:29:54 -0000
@@ -4,6 +4,7 @@
 	utility.o global.o authenc.o logwtmp.o logout.o
 
 CFLAGS += -DPARANOID_TTYS -DUSE_TERMIO -DKLUDGELINEMODE -D_GNU_SOURCE
+LDLIBS := -lutil $(LDLIBS)
 
 all: $(EXEC)
 
diff -u -r1.1.1.2 sys_term.c
--- user/telnetd/sys_term.c	28 Feb 2003 22:47:41 -0000	1.1.1.2
+++ user/telnetd/sys_term.c	19 Jul 2003 17:29:54 -0000
@@ -31,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)sys_term.c	5.16 (Berkeley) 3/22/91
- */
-char st_rcsid[] = 
-  "$Id: sys_term.c,v 1.1.1.2 2003/02/28 22:47:41 bernie Exp $";
-
 #include "telnetd.h"
 #include "pathnames.h"
 #include "logout.h"
@@ -46,6 +40,10 @@
 #include <libtelnet/auth.h>
 #endif
 
+#ifdef __UCLIBC__
+#include "pty.h"
+#endif /* __UCLIBC__ */
+
 #ifdef NEWINIT
 #include <initreq.h>
 
@@ -420,11 +418,22 @@
  */
 static char Xline[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 char *line = 0;
+
+int ptyslavefd = -1;
+
 #ifdef	CRAY
 char *myline = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 #endif	/* CRAY */
 
 int getpty(void) {
+#ifdef __UCLIBC__
+	int ptymasterfd;
+	if (openpty(&ptymasterfd, &ptyslavefd, line, NULL, NULL))
+		return -1;
+	return ptymasterfd;
+
+#else /* !__UCLIBC__ */
+
     int p;
 #ifndef CRAY
     char *p1, *p2;
@@ -491,6 +500,7 @@
     }
 #endif	/* CRAY */
     return(-1);
+#endif /* !__UCLIBC__ */
 }
 #endif	/* convex */
 
@@ -822,6 +832,35 @@
 extern int def_tspeed, def_rspeed;
 
 static int getptyslave(void) {
+#ifdef __UCLIBC__
+	struct winsize ws;
+	int t = ptyslavefd;
+
+        init_termbuf();
+
+	if (def_row || def_col) {
+		memset((char *)&ws, 0, sizeof(ws));
+		ws.ws_col = def_col;
+		ws.ws_row = def_row;
+		ioctl(t, TIOCSWINSZ, (char *)&ws);
+	}
+
+	set_termbuf();
+
+	tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
+	tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
+
+	if (login_tty(t) == -1)
+		fatalperror(net, "login_tty");
+	if (net > 2)
+		close(net);
+	if (pty > 2)
+		close(pty);
+
+	return t;
+
+#else /* !__UCLIBC__ */
+
     register int t = -1;
 
 #if !defined(CRAY) || !defined(NEWINIT)
@@ -926,9 +965,11 @@
     if (net > 2) close(net);
     if (pty > 2) close(pty);
     return t;  /* ? was nothing here... */
+
+#endif /* __UCLIBC__ */
 }
 
-#if !defined(CRAY) || !defined(NEWINIT)
+#if !defined(CRAY) || !defined(NEWINIT) || !defined(__UCLIBC__)
 #ifndef	O_NOCTTY
 #define	O_NOCTTY	0
 #endif
@@ -981,7 +1022,7 @@
 # endif	/* defined(CRAY) && defined(TCVHUP) */
     return(t);
 }
-#endif	/* !defined(CRAY) || !defined(NEWINIT) */
+#endif	/* !defined(CRAY) || !defined(NEWINIT) || !defined(__UCLIBC__) */
 
 #if BSD <= 43
 int login_tty(int t) {
diff -u -r1.1.1.2 telnetd.c
--- user/telnetd/telnetd.c	28 Feb 2003 22:47:41 -0000	1.1.1.2
+++ user/telnetd/telnetd.c	19 Jul 2003 17:29:54 -0000
@@ -31,16 +31,6 @@
  * SUCH DAMAGE.
  */
 
-char copyright[] =
-  "@(#) Copyright (c) 1989 Regents of the University of California.\n"
-  "All rights reserved.\n";
-
-/*
- * From: @(#)telnetd.c	5.48 (Berkeley) 3/1/91
- */
-char telnetd_rcsid[] = 
-  "$Original-Id: telnetd.c,v 1.9 1996/12/29 18:16:33 dholland Exp $";
-
 #include <netdb.h>
 #ifdef TERMCAP
 #include <termcap.h>
@@ -83,7 +73,9 @@
 char *loginprg = _PATH_LOGIN;
 char *progname;
 
-extern void usage(void);
+#ifndef EMBED
+static void usage(void);
+#endif /* EMBED */
 
 int
 main(int argc, char *argv[])
@@ -390,7 +382,8 @@
 	return 0;
 }  /* end of main */
 
-void
+#ifndef EMBED
+static void
 usage(void)
 {
 	fprintf(stderr, "Usage: telnetd");
@@ -428,6 +421,7 @@
 	fprintf(stderr, " [port]\n");
 	exit(1);
 }
+#endif /* EMBED */
 
 /*
  * getterminaltype
diff -u -r1.1.1.1 termstat.c
--- user/telnetd/termstat.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/termstat.c	19 Jul 2003 17:29:54 -0000
@@ -31,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)termstat.c	5.10 (Berkeley) 3/22/91
- */
-char termstat_rcsid[] = 
-  "$Id: termstat.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
 #include "telnetd.h"
 
 /*
diff -u -r1.1.1.1 utility.c
--- user/telnetd/utility.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/utility.c	19 Jul 2003 17:29:54 -0000
@@ -31,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)utility.c	5.8 (Berkeley) 3/22/91
- */
-char util_rcsid[] = 
-  "$Id: utility.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
 #define PRINTOPTIONS
 
 #include <sys/utsname.h>
diff -u -r1.1.1.1 authenc.c
--- user/telnetd/authenc.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/authenc.c	19 Jul 2003 17:29:54 -0000
@@ -17,12 +17,6 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-/*
- * From: @(#)authenc.c	5.1 (Berkeley) 3/1/91
- */
-char authenc_rcsid[] =
-  "$Id: authenc.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
 #if	defined(ENCRYPT) || defined(AUTHENTICATE)
 #include "telnetd.h"
 #include <libtelnet/misc.h>
diff -u -r1.1.1.1 global.c
--- user/telnetd/global.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/global.c	19 Jul 2003 17:29:54 -0000
@@ -32,12 +32,6 @@
  */
 
 /*
- * From: @(#)global.c	5.2 (Berkeley) 6/1/90
- */
-char global_rcsid[] = 
-  "$Id: global.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
-/*
  * Allocate global variables.  
  */
 
diff -u -r1.1.1.1 logout.c
--- user/telnetd/logout.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/logout.c	19 Jul 2003 17:29:54 -0000
@@ -31,13 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)logout.c	8.1 (Berkeley) 6/4/93
- * From: NetBSD: logout.c,v 1.5 1996/05/15 21:42:28 jtc Exp
- */
-char rcsid_logout[] = 
-  "$Id";
-
 #include <sys/types.h>
 #include <sys/time.h>
 
diff -u -r1.1.1.1 slc.c
--- user/telnetd/slc.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/slc.c	19 Jul 2003 17:29:54 -0000
@@ -31,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)slc.c	5.7 (Berkeley) 3/1/91
- */
-char slc_rcsid[] = 
-  "$Id: slc.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
 #include "telnetd.h"
 
 #ifdef LINEMODE
diff -u -r1.1.1.1 state.c
--- user/telnetd/state.c	22 Jan 2002 00:32:17 -0000	1.1.1.1
+++ user/telnetd/state.c	19 Jul 2003 17:29:54 -0000
@@ -31,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-/*
- * From: @(#)state.c	5.10 (Berkeley) 3/22/91
- */
-char state_rcsid[] = 
-  "$Id: state.c,v 1.1.1.1 2002/01/22 00:32:17 bernie Exp $";
-
 #include "telnetd.h"
 
 int not42 = 1;
