]> Pileus Git - ~andy/fetchmail/commitdiff
Deal with connect(2) bug.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 1 Nov 1996 18:05:40 +0000 (18:05 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 1 Nov 1996 18:05:40 +0000 (18:05 -0000)
svn path=/trunk/; revision=465

driver.c
fetchmail.man
socket.c

index 84e557f3da1d482917f2afdf711ca541f42d1100..1c8408e177b06897ddee9724c5e034d526d021e7 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -874,7 +874,7 @@ const struct method *proto; /* protocol method table */
 
        /* open a socket to the mail server */
        if ((sockfp = Socket(ctl->servername,
-                            ctl->port ? ctl->port : protocol->port))<0)
+                            ctl->port ? ctl->port : protocol->port)) == (FILE *)NULL)
        {
            perror("fetchmail, connecting to host");
            ok = PS_SOCKET;
index bfd6b387aabb459bc841382c005911867383ad5a..7e78b80f23728f10d45dd56e33386b58abc6bb27 100644 (file)
@@ -701,16 +701,6 @@ catch equivalences created by MX records).  If it is an alias of the
 server, but the lookup fails due to network congestion or a crashed
 server, forwarding will not get done correctly.
 .PP
-Under Linux, if fetchmail is run in daemon mode with the network
-inaccessible, each poll leaves a socket allocated but in CLOSE state
-(this is visible in netstat(1)'s output).  For some reason, these
-sockets aren't garbage-collected until \fIfetchmail\fR exits.  When
-whatever kernel table is involved fills up, fetchmail can no longer
-run even if the network is up.  This appears \fInot\fR to be a socket
-leak in \fIfetchmail\fR, but rather some glitch or misfeature in the system
-network code.  To avoid this problem, fetchmail commits seppuku after
-too many unsuccessful socket opens.
-.PP
 Send comments, bug reports, gripes, and the like to Eric S. Raymond
 <esr@thyrsus.com>.
 .SH SEE ALSO
index f0020adf777c23edffd63b55976df5da5c808b70..9d716dcb076e8f5742e47392fc0db7dd4a55453b 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -51,8 +51,19 @@ int clientPort;
     sock = socket(AF_INET, SOCK_STREAM, 0);
     if (sock < 0)
         return (FILE *)NULL;
-    if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
+
+    /*
+     * Return of connect(2) doesn't seem to reliably return -1 on 
+     * ENETUNREACH failure
+     */
+    errno = 0;
+    connect(sock, (struct sockaddr *) &ad, sizeof(ad));
+    if (errno != 0);
+    {
+       close(sock);
         return (FILE *)NULL;
+    }
+
     return fdopen(sock, "r+");
 }