Subject: Never ending connections

From: David Hinds <[email-masked]>
Date: Wed, 3 May 1995 10:47:12 -0700 (PDT)

This patch seems to fix our problems with hung wu-ftpd-2.4 processes
due to unexpected loss of connections.  Unlike the other solutions
mentioned, this does not interfere with legitimate connections over
slow links.

	-- Dave Hinds
	   [email-masked]

--- src/ftpd.c~	Mon Apr 10 12:03:14 1995
+++ src/ftpd.c	Sun Apr 23 17:04:30 1995
@@ -1690,6 +1690,13 @@
     return (NULL);
 }
 
+static void
+toolong()
+{
+    reply(425, "Can't open data connection -- timed out.");
+    dologout(1);
+}
+
 FILE *
 dataconn(char *name, off_t size, char *mode)
 {
@@ -1711,7 +1718,10 @@
         int s,
           fromlen = sizeof(from);
 
+	(void) signal(SIGALRM, toolong);
+	(void) alarm((unsigned) timeout);
         s = accept(pdata, (struct sockaddr *) &from, &fromlen);
+	(void) alarm(0);
         if (s < 0) {
             reply(425, "Can't open data connection.");
             (void) close(pdata);