Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ftpd Set keepalives on the sockets to force logouts ...



details:   https://anonhg.NetBSD.org/src/rev/a26e4acdb9d0
branches:  trunk
changeset: 473482:a26e4acdb9d0
user:      briggs <briggs%NetBSD.org@localhost>
date:      Sat Jun 05 13:49:53 1999 +0000

description:
Set keepalives on the sockets to force logouts on connections that have
disappeared.

diffstat:

 libexec/ftpd/ftpd.c |  24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diffs (73 lines):

diff -r e97bfbc00967 -r a26e4acdb9d0 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Sat Jun 05 13:43:03 1999 +0000
+++ b/libexec/ftpd/ftpd.c       Sat Jun 05 13:49:53 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.65 1999/05/24 21:57:19 ross Exp $   */
+/*     $NetBSD: ftpd.c,v 1.66 1999/06/05 13:49:53 briggs Exp $ */
 
 /*
  * Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994
@@ -80,7 +80,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.65 1999/05/24 21:57:19 ross Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.66 1999/06/05 13:49:53 briggs Exp $");
 #endif
 #endif /* not lint */
 
@@ -237,7 +237,7 @@
        int argc;
        char *argv[];
 {
-       int addrlen, ch, on = 1, tos;
+       int addrlen, ch, on = 1, tos, keepalive;
        char *cp, line[LINE_MAX];
        FILE *fd;
 #ifdef KERBEROS5  
@@ -328,6 +328,13 @@
        if (setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)) < 0)
                syslog(LOG_ERR, "setsockopt: %m");
 #endif
+       /* Set keepalives on the socket to detect dropped connections.  */
+#ifdef SO_KEEPALIVE
+       keepalive = 1;
+       if (setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive,
+           sizeof(int)) < 0)
+               syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
+#endif
 
 #ifdef F_SETOWN
        if (fcntl(fileno(stdin), F_SETOWN, getpid()) == -1)
@@ -1021,6 +1028,9 @@
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
            (char *) &on, sizeof(on)) < 0)
                goto bad;
+       if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
+           (char *) &on, sizeof(on)) < 0)
+               goto bad;
        /* anchor socket to avoid multi-homing problems */
        data_source.sin_len = sizeof(struct sockaddr_in);
        data_source.sin_family = AF_INET;
@@ -1057,7 +1067,7 @@
 {
        char sizebuf[32];
        FILE *file;
-       int retry = 0, tos;
+       int retry = 0, tos, keepalive;
 
        file_size = size;
        byte_count = 0;
@@ -1086,6 +1096,12 @@
                (void) setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
                    sizeof(int));
 #endif
+               /* Set keepalives on the socket to detect dropped conns. */
+#ifdef SO_KEEPALIVE
+               keepalive = 1;
+               (void) setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
+                   (char *)&keepalive, sizeof(int));
+#endif
                reply(150, "Opening %s mode data connection for '%s'%s.",
                     type == TYPE_A ? "ASCII" : "BINARY", name, sizebuf);
                return (fdopen(pdata, mode));



Home | Main Index | Thread Index | Old Index