[bug] forcing telnetd to exit and loose all other sessions

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Tue Sep 26 09:06:00 UTC 2006


On Tue, 26 Sep 2006, Cristian Ionescu-Idbohrn wrote:

> Please find attached a WFM patch against bb-1.1.3 which should resolv
> the reported problem. Comments anyone?

And the only thing missing was tha patch, of course.


Cheers,
Cristian
-------------- next part --------------
--- telnetd.c.orig	2006-06-29 18:18:07.000000000 +0200
+++ telnetd.c	2006-09-26 10:40:56.000000000 +0200
@@ -107,6 +107,18 @@ static int maxfd;
 
 static struct tsession *sessions;
 
+#ifndef CONFIG_FEATURE_TELNETD_INETD
+/*
+ * Detect lost connection with the client.
+ */
+static int lost_connection = 0;
+static void
+sigpipe_handler(int sig __attribute__ ((unused))) {
+	lost_connection = 1;
+	syslog(LOG_INFO, "client connection lost");
+	(void)signal(SIGPIPE, sigpipe_handler);
+}
+#endif /* CONFIG_FEATURE_TELNETD_INETD */
 
 /*
 
@@ -397,7 +409,7 @@ telnetd_main(int argc, char **argv)
 	static const char options[] =
 #ifdef CONFIG_FEATURE_TELNETD_INETD
 		"f:l:";
-#else /* CONFIG_EATURE_TELNETD_INETD */
+#else /* CONFIG_FEATURE_TELNETD_INETD */
 		"f:l:p:b:";
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
 	int maxlen, w, r;
@@ -430,6 +442,10 @@ telnetd_main(int argc, char **argv)
 		}
 	}
 
+#ifndef CONFIG_FEATURE_TELNETD_INETD
+	(void)signal(SIGPIPE, sigpipe_handler);
+#endif /* CONFIG_FEATURE_TELNETD_INETD */
+
 	if (access(loginpath, X_OK) < 0) {
 		bb_error_msg_and_die ("'%s' unavailable.", loginpath);
 	}
@@ -441,7 +457,7 @@ telnetd_main(int argc, char **argv)
 #ifdef CONFIG_FEATURE_TELNETD_INETD
 	maxfd = 1;
 	sessions = make_new_session();
-#else /* CONFIG_EATURE_TELNETD_INETD */
+#else /* CONFIG_FEATURE_TELNETD_INETD */
 	sessions = 0;
 
 	/* Grab a TCP socket.  */
@@ -600,7 +616,9 @@ telnetd_main(int argc, char **argv)
 					exit(0);
 #else /* CONFIG_FEATURE_TELNETD_INETD */
 				w = write(ts->sockfd, ts->buf2 + ts->wridx2, maxlen);
-				if (w < 0) {
+				if (w < 0 || lost_connection) {
+					if (lost_connection)
+						lost_connection = 0;
 					free_session(ts);
 					ts = next;
 					continue;


More information about the busybox mailing list