Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp If connect(2) in xconnect() fails with EINTR, ca...



details:   https://anonhg.NetBSD.org/src/rev/3fa519195bce
branches:  trunk
changeset: 565482:3fa519195bce
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Apr 10 12:21:39 2004 +0000

description:
If connect(2) in xconnect() fails with EINTR, call select(2) on the socket
until it's writable or it fails with something other than EINTR.
This matches the behaviour in SUSv3, and prevents the problem when
pressing ^T (SIGINFO, which is marked as restartable) during connection
setup would cause ftp to fail with EADDRINUSE or EALREADY when the
second connect(2) was attempted on the same socket.
Problem found and solution provided by Maxime Henrion <mux%freebsd.org@localhost>.

diffstat:

 usr.bin/ftp/ftp.c     |  11 +++--------
 usr.bin/ftp/util.c    |  23 +++++++++++++++++++----
 usr.bin/ftp/version.h |   4 ++--
 3 files changed, 24 insertions(+), 14 deletions(-)

diffs (105 lines):

diff -r ef7d732a8bf0 -r 3fa519195bce usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Sat Apr 10 12:02:43 2004 +0000
+++ b/usr.bin/ftp/ftp.c Sat Apr 10 12:21:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.124 2004/04/10 12:02:43 lukem Exp $  */
+/*     $NetBSD: ftp.c,v 1.125 2004/04/10 12:21:39 lukem Exp $  */
 
 /*-
  * Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c      8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.124 2004/04/10 12:02:43 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.125 2004/04/10 12:21:39 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -230,10 +230,7 @@
                        cause = "socket";
                        continue;
                }
-               while ((error = xconnect(s, res->ai_addr, res->ai_addrlen)) < 0
-                               && errno == EINTR) {
-                       ;
-               }
+               error = xconnect(s, res->ai_addr, res->ai_addrlen);
                if (error) {
                        /* this "if" clause is to prevent print warning twice */
                        if (res->ai_next) {
@@ -1546,8 +1543,6 @@
 
                while (xconnect(data, (struct sockaddr *)&data_addr.si_su,
                            data_addr.su_len) < 0) {
-                       if (errno == EINTR)
-                               continue;
                        if (activefallback) {
                                (void)close(data);
                                data = -1;
diff -r ef7d732a8bf0 -r 3fa519195bce usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Sat Apr 10 12:02:43 2004 +0000
+++ b/usr.bin/ftp/util.c        Sat Apr 10 12:21:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.114 2003/08/07 11:13:57 agc Exp $   */
+/*     $NetBSD: util.c,v 1.115 2004/04/10 12:21:39 lukem Exp $ */
 
 /*-
  * Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.114 2003/08/07 11:13:57 agc Exp $");
+__RCSID("$NetBSD: util.c,v 1.115 2004/04/10 12:21:39 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -1203,14 +1203,29 @@
 
 
 /*
- * Internal version of connect(2); sets socket buffer sizes first.
+ * Internal version of connect(2); sets socket buffer sizes first and
+ * handles the syscall being interrupted.
+ * Returns -1 upon failure (with errno set to the problem), or 0 on success.
  */
 int
 xconnect(int sock, const struct sockaddr *name, int namelen)
 {
+       int     rv;
 
        setupsockbufsize(sock);
-       return (connect(sock, name, namelen));
+       rv = connect(sock, name, namelen);
+       if (rv == -1 && errno == EINTR) {
+               fd_set  connfd;
+
+               FD_ZERO(&connfd);
+               FD_SET(sock, &connfd);
+               do {
+                       rv = select(sock + 1, NULL, &connfd, NULL, NULL);
+               } while (rv == -1 && errno == EINTR);
+               if (rv > 0)
+                       rv = 0;
+       }
+       return (rv);
 }
 
 /*
diff -r ef7d732a8bf0 -r 3fa519195bce usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Sat Apr 10 12:02:43 2004 +0000
+++ b/usr.bin/ftp/version.h     Sat Apr 10 12:21:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.34 2003/12/10 12:34:29 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.35 2004/04/10 12:21:39 lukem Exp $       */
 /*-
  * Copyright (c) 1999-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -40,5 +40,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20031210"
+#define        FTP_VERSION     "20040410"
 #endif



Home | Main Index | Thread Index | Old Index