You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/01/09 17:46:01 UTC

svn commit: r494481 - in /spamassassin/trunk/spamc: libspamc.c libspamc.h spamc.c spamc.pod

Author: jm
Date: Tue Jan  9 08:46:01 2007
New Revision: 494481

URL: http://svn.apache.org/viewvc?view=rev&rev=494481
Log:
bug 4471: add --connect-retries and --retry-sleep switches to spamc, thanks to John Madden <maddenj+spamassassin at skynet.ie>

Modified:
    spamassassin/trunk/spamc/libspamc.c
    spamassassin/trunk/spamc/libspamc.h
    spamassassin/trunk/spamc/spamc.c
    spamassassin/trunk/spamc/spamc.pod

Modified: spamassassin/trunk/spamc/libspamc.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/libspamc.c?view=diff&rev=494481&r1=494480&r2=494481
==============================================================================
--- spamassassin/trunk/spamc/libspamc.c (original)
+++ spamassassin/trunk/spamc/libspamc.c Tue Jan  9 08:46:01 2007
@@ -61,10 +61,6 @@
 #include <zlib.h>
 #endif
 
-/* FIXME: Make this configurable */
-#define MAX_CONNECT_RETRIES 3
-#define CONNECT_RETRY_SLEEP 1
-
 /* RedHat 5.2 doesn't define Shutdown 2nd Parameter Constants */
 /* KAM 12-4-01 */
 /* SJF 2003/04/25 - now test for macros directly */
@@ -442,11 +438,23 @@
     char host[SPAMC_MAXHOST-1]; /* hostname, for logging */
     char port[SPAMC_MAXSERV-1]; /* port, for logging */
 
+    int connect_retries, retry_sleep;
+
     assert(tp != 0);
     assert(sockptr != 0);
     assert(tp->nhosts > 0);
 
-    for (numloops = 0; numloops < MAX_CONNECT_RETRIES; numloops++) {
+    // default values
+    retry_sleep = tp->retry_sleep;
+    connect_retries = tp->connect_retries;
+    if (connect_retries == 0) {
+      connect_retries = 3;
+    }
+    if (retry_sleep == 0) {
+      retry_sleep = 1;
+    }
+
+    for (numloops = 0; numloops < connect_retries; numloops++) {
         const int hostix = numloops % tp->nhosts;
         int status, mysock;
 
@@ -485,7 +493,7 @@
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
             libspamc_log(tp->flags, CONNECT_DEBUG_LEVEL,
               "dbg: connect(%s) to spamd (host %s, port %s) (try #%d of %d)",
-                      family, host, port, numloops + 1, MAX_CONNECT_RETRIES);
+                      family, host, port, numloops + 1, connect_retries);
 #endif
 
             status = timeout_connect(mysock, res->ai_addr, res->ai_addrlen);
@@ -506,7 +514,7 @@
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
 	    libspamc_log(tp->flags, LOG_DEBUG,
 			 "dbg: connect(AF_INET) to spamd at %s (try #%d of %d)",
-			 ipaddr, numloops + 1, MAX_CONNECT_RETRIES);
+			 ipaddr, numloops + 1, connect_retries);
 #endif
 	    
 	    status =
@@ -521,11 +529,11 @@
 #ifndef _WIN32
                   libspamc_log(tp->flags, LOG_ERR,
                       "connect to spamd on %s failed, retrying (#%d of %d): %s",
-                      host, numloops+1, MAX_CONNECT_RETRIES, strerror(origerr));
+                      host, numloops+1, connect_retries, strerror(origerr));
 #else
                   libspamc_log(tp->flags, LOG_ERR,
                       "connect to spamd on %s failed, retrying (#%d of %d): %d",
-                      host, numloops+1, MAX_CONNECT_RETRIES, origerr);
+                      host, numloops+1, connect_retries, origerr);
 #endif
 
             } else {
@@ -541,7 +549,7 @@
             res = res->ai_next;
         }
 #endif
-        sleep(CONNECT_RETRY_SLEEP);
+        sleep(retry_sleep);
     } /* for(numloops...) */
 
 #ifdef SPAMC_HAS_ADDRINFO
@@ -552,7 +560,7 @@
 
     libspamc_log(tp->flags, LOG_ERR,
               "connection attempt to spamd aborted after %d retries",
-              MAX_CONNECT_RETRIES);
+              connect_retries);
 
     return _translate_connect_errno(origerr);
 }

Modified: spamassassin/trunk/spamc/libspamc.h
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/libspamc.h?view=diff&rev=494481&r1=494480&r2=494481
==============================================================================
--- spamassassin/trunk/spamc/libspamc.h (original)
+++ spamassassin/trunk/spamc/libspamc.h Tue Jan  9 08:46:01 2007
@@ -226,6 +226,10 @@
 #endif
     int nhosts;
     int flags;
+
+    /* added in SpamAssassin 3.2.0 */
+    int connect_retries;
+    int retry_sleep;
 };
 
 extern void transport_init(struct transport *tp);

Modified: spamassassin/trunk/spamc/spamc.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/spamc.c?view=diff&rev=494481&r1=494480&r2=494481
==============================================================================
--- spamassassin/trunk/spamc/spamc.c (original)
+++ spamassassin/trunk/spamc/spamc.c Tue Jan  9 08:46:01 2007
@@ -153,6 +153,11 @@
     usg("  -t, --timeout timeout\n"
         "                      Timeout in seconds for communications to\n"
         "                      spamd. [default: 600]\n");
+    usg("  --connect-retries retries\n"
+        "                      Try connecting to spamd this many times\n"
+        "                      [default: 3]\n");
+    usg("  --retry-sleep sleep Sleep for this time between attempts to\n"
+        "                      connect to spamd, in seconds [default: 1]\n");
     usg("  -s, --max-size size Specify maximum message size, in bytes.\n"
         "                      [default: 500k]\n");
     usg("  -u, --username username\n"
@@ -209,9 +214,9 @@
           struct transport *ptrn)
 {
 #ifndef _WIN32
-    const char *opts = "-BcrRd:e:fyp:t:s:u:L:C:xzSHU:ElhVKF:";
+    const char *opts = "-BcrRd:e:fyp:t:s:u:L:C:xzSHU:ElhVKF:0:1:";
 #else
-    const char *opts = "-BcrRd:fyp:t:s:u:L:C:xzSHElhVKF:";
+    const char *opts = "-BcrRd:fyp:t:s:u:L:C:xzSHElhVKF:0:1:";
 #endif
     int opt;
     int ret = EX_OK;
@@ -225,6 +230,8 @@
        { "socket", required_argument, 0, 'U' },
        { "config", required_argument, 0, 'F' },
        { "timeout", required_argument, 0, 't' },
+       { "connect-retries", required_argument, 0, 0 },
+       { "retry-sleep", required_argument, 0, 1 },
        { "max-size", required_argument, 0, 's' },
        { "username", required_argument, 0, 'u' },
        { "learntype", required_argument, 0, 'L' },
@@ -438,6 +445,16 @@
             case 'z':
             {
                 flags |= SPAMC_USE_ZLIB;
+                break;
+            }
+            case 0:
+            {
+                ptrn->connect_retries = atoi(spamc_optarg);
+                break;
+            }
+            case 1:
+            {
+                ptrn->retry_sleep = atoi(spamc_optarg);
                 break;
             }
         }

Modified: spamassassin/trunk/spamc/spamc.pod
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamc/spamc.pod?view=diff&rev=494481&r1=494480&r2=494481
==============================================================================
--- spamassassin/trunk/spamc/spamc.pod (original)
+++ spamassassin/trunk/spamc/spamc.pod Tue Jan  9 08:46:01 2007
@@ -157,6 +157,15 @@
 The size is specified in bytes, as a positive integer greater than 0.
 For example, B<-s 500000>. 
 
+=item B<--connect-retries>=I<retries>
+
+Retry connecting to spamd I<retries> times.  The default is 3 times.
+
+=item B<--retry-sleep>=I<sleep>
+
+Sleep for I<sleep> seconds between attempts to connect to spamd.
+The default is 1 second.
+
 =item B<-S>, B<--ssl>, B<--ssl>=I<sslversion>
 
 If spamc was built with support for SSL, encrypt data to and from the