From 343eedd542a30c183f2d134b7668d07cab0a5769 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 1 Nov 1996 18:05:40 +0000 Subject: Deal with connect(2) bug. svn path=/trunk/; revision=465 --- driver.c | 2 +- fetchmail.man | 10 ---------- socket.c | 13 ++++++++++++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/driver.c b/driver.c index 84e557f3..1c8408e1 100644 --- 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; diff --git a/fetchmail.man b/fetchmail.man index bfd6b387..7e78b80f 100644 --- a/fetchmail.man +++ b/fetchmail.man @@ -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 . .SH SEE ALSO diff --git a/socket.c b/socket.c index f0020adf..9d716dcb 100644 --- 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+"); } -- cgit v1.2.3