Browse code

Handle load balancing better when one machine of the cluster is down

git-svn: trunk@2200

Nigel Horne authored on 2006/08/18 23:41:14
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Fri Aug 18 15:40:30 BST 2006 (njh)
2
+----------------------------------
3
+  * clamav-milter:	Handle load balancing better when one machine of the
4
+				cluster is down
5
+
1 6
 Wed Aug 16 00:41:30 CEST 2006 (tk)
2 7
 ----------------------------------
3 8
   * freshclam/manager.c: correctly remove patches after applying
... ...
@@ -23,9 +23,9 @@
23 23
  *
24 24
  * For installation instructions see the file INSTALL that came with this file
25 25
  */
26
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.276 2006/08/07 06:44:52 njh Exp $";
26
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.277 2006/08/18 14:40:18 njh Exp $";
27 27
 
28
-#define	CM_VERSION	"devel-070806"
28
+#define	CM_VERSION	"devel-180806"
29 29
 
30 30
 #if HAVE_CONFIG_H
31 31
 #include "clamav-config.h"
... ...
@@ -2105,7 +2105,7 @@ static int
2105 2105
 findServer(void)
2106 2106
 {
2107 2107
 	struct sockaddr_in *servers, *server;
2108
-	int *socks, maxsock = 0, i, j;
2108
+	int *socks, maxsock = -1, i, j;
2109 2109
 	fd_set rfds;
2110 2110
 	int retval;
2111 2111
 
... ...
@@ -2116,6 +2116,8 @@ findServer(void)
2116 2116
 		return 0;
2117 2117
 
2118 2118
 	servers = (struct sockaddr_in *)cli_calloc(numServers, sizeof(struct sockaddr_in));
2119
+	if(servers == NULL)
2120
+		return 0;
2119 2121
 	socks = (int *)cli_malloc(numServers * sizeof(int));
2120 2122
 
2121 2123
 	FD_ZERO(&rfds);
... ...
@@ -2190,9 +2192,10 @@ findServer(void)
2190 2190
 
2191 2191
 	free(servers);
2192 2192
 
2193
-	if(maxsock == 0)
2193
+	if(maxsock == -1) {
2194
+		logg(_("^Couldn't establish a connection to any clamd server\n"));
2194 2195
 		retval = 0;
2195
-	else {
2196
+	} else {
2196 2197
 		struct timeval tv;
2197 2198
 
2198 2199
 		tv.tv_sec = readTimeout ? readTimeout : DEFAULT_TIMEOUT;
... ...
@@ -2229,9 +2232,7 @@ findServer(void)
2229 2229
 		}
2230 2230
 
2231 2231
 	free(socks);
2232
-	cli_dbgmsg(_("findServer: No response from any server\n"));
2233
-	if(use_syslog)
2234
-		syslog(LOG_WARNING, _("findServer: No response from any server"));
2232
+	logg(_("^findServer: No response from any server\n"));
2235 2233
 	return 0;
2236 2234
 }
2237 2235
 #endif
... ...
@@ -2436,7 +2437,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2436 2436
 	if(smfi_getpriv(ctx) != NULL) {
2437 2437
 		/* More than one connection command, "can't happen" */
2438 2438
 		cli_warnmsg("clamfi_connect: called more than once\n");
2439
-		return SMFIS_TEMPFAIL;
2439
+		return cl_error;
2440 2440
 	}
2441 2441
 
2442 2442
 	if(blacklist_time == 0)
... ...
@@ -5245,6 +5246,7 @@ loadDatabase(void)
5245 5245
 
5246 5246
 		cl_cvdfree(d);
5247 5247
 	} else
5248
+		/* TODO: use dbdir/daily.inc/daily.info */
5248 5249
 		snprintf(clamav_version, VERSION_LENGTH,
5249 5250
 			"ClamAV version %s, clamav-milter version %s",
5250 5251
 			VERSION, CM_VERSION);