summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil Pennock <pdp@exim.org>2011-02-21 00:11:32 -0500
committerPhil Pennock <pdp@exim.org>2011-02-21 00:13:18 -0500
commit29cfeb94e35eb8fe2b6f02fe9c9444edb251fd71 (patch)
tree287642bd0a2fada4e4ab79d13c7d619c52239947 /src
parent332f5cf3ddb43e1a85d70039211e73aa1a753ebd (diff)
Improved spamd server selection.
Patch from Mark Zealey. Fixes bug 1056.
Diffstat (limited to 'src')
-rw-r--r--src/src/spam.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/src/spam.c b/src/src/spam.c
index ac9642028..55999a397 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -111,10 +111,8 @@ int spam(uschar **listptr) {
/* socket does not start with '/' -> network socket */
if (*spamd_address_work != '/') {
- time_t now = time(NULL);
int num_servers = 0;
- int current_server = 0;
- int start_server = 0;
+ int current_server;
uschar *address = NULL;
uschar *spamd_address_list_ptr = spamd_address_work;
uschar address_buffer[256];
@@ -126,6 +124,7 @@ int spam(uschar **listptr) {
address_buffer,
sizeof(address_buffer))) != NULL) {
+ /* Potential memory leak as we never free the store. */
spamd_address_container *this_spamd =
(spamd_address_container *)store_get(sizeof(spamd_address_container));
@@ -150,9 +149,10 @@ int spam(uschar **listptr) {
return DEFER;
};
- current_server = start_server = (int)now % num_servers;
+ while ( num_servers > 0 ) {
- while (1) {
+ /* Randomly pick a server to try */
+ current_server = random_number( num_servers );
debug_printf("trying server %s, port %u\n",
spamd_address_vector[current_server]->tcp_addr,
@@ -180,16 +180,21 @@ int spam(uschar **listptr) {
spamd_address_vector[current_server]->tcp_addr,
spamd_address_vector[current_server]->tcp_port,
strerror(errno));
- current_server++;
- if (current_server >= num_servers)
- current_server = 0;
- if (current_server == start_server) {
- log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
- (void)fclose(mbox_file);
- (void)close(spamd_sock);
- return DEFER;
- };
- };
+
+ (void)close(spamd_sock);
+
+ /* Remove the server from the list. XXX We should free the memory */
+ num_servers--;
+ int i;
+ for( i = current_server; i < num_servers; i++ )
+ spamd_address_vector[i] = spamd_address_vector[i+1];
+ }
+
+ if ( num_servers == 0 ) {
+ log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
+ (void)fclose(mbox_file);
+ return DEFER;
+ }
}
else {