spamassassin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sid...@apache.org
Subject svn commit: r384582 - in /spamassassin/branches/3.1/spamc: libspamc.c utils.c utils.h
Date Thu, 09 Mar 2006 18:54:50 GMT
Author: sidney
Date: Thu Mar  9 10:54:48 2006
New Revision: 384582

URL: http://svn.apache.org/viewcvs?rev=384582&view=rev
Log:
bug 3710: add timeout to connect so spamc -t works

Modified:
    spamassassin/branches/3.1/spamc/libspamc.c
    spamassassin/branches/3.1/spamc/utils.c
    spamassassin/branches/3.1/spamc/utils.h

Modified: spamassassin/branches/3.1/spamc/libspamc.c
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/spamc/libspamc.c?rev=384582&r1=384581&r2=384582&view=diff
==============================================================================
--- spamassassin/branches/3.1/spamc/libspamc.c (original)
+++ spamassassin/branches/3.1/spamc/libspamc.c Thu Mar  9 10:54:48 2006
@@ -193,7 +193,7 @@
     }
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-    libspamc_log(flags, DEBUG_LEVEL, "dbg: create socket(%s)", typename);
+    libspamc_log(flags, LOG_DEBUG, "dbg: create socket(%s)", typename);
 #endif
 
     if ((*psock = socket(type, SOCK_STREAM, proto))
@@ -334,17 +334,17 @@
     addrbuf.sun_path[sizeof addrbuf.sun_path - 1] = '\0';
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-    libspamc_log(tp->flags, DEBUG_LEVEL, "dbg: connect(AF_UNIX) to spamd at %s",
+    libspamc_log(tp->flags, LOG_DEBUG, "dbg: connect(AF_UNIX) to spamd at %s",
 	   addrbuf.sun_path);
 #endif
 
-    status = connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
+    status = timeout_connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
 
     origerr = errno;
 
     if (status >= 0) {
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-	libspamc_log(tp->flags, DEBUG_LEVEL, "dbg: connect(AF_UNIX) ok");
+	libspamc_log(tp->flags, LOG_DEBUG, "dbg: connect(AF_UNIX) ok");
 #endif
 
 	*sockptr = mysock;
@@ -412,13 +412,13 @@
 	ipaddr = inet_ntoa(addrbuf.sin_addr);
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-	libspamc_log(tp->flags, DEBUG_LEVEL,
+	libspamc_log(tp->flags, LOG_DEBUG,
 	       "dbg: connect(AF_INET) to spamd at %s (try #%d of %d)",
 		ipaddr, numloops + 1, MAX_CONNECT_RETRIES);
 #endif
 
 	status =
-	    connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
+	    timeout_connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
 
 	if (status != 0) {
 #ifndef _WIN32
@@ -438,7 +438,7 @@
 	}
 	else {
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-	    libspamc_log(tp->flags, DEBUG_LEVEL,
+	    libspamc_log(tp->flags, LOG_DEBUG,
 		   "dbg: connect(AF_INET) to spamd at %s done", ipaddr);
 #endif
 	    *sockptr = mysock;

Modified: spamassassin/branches/3.1/spamc/utils.c
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/spamc/utils.c?rev=384582&r1=384581&r2=384582&view=diff
==============================================================================
--- spamassassin/branches/3.1/spamc/utils.c (original)
+++ spamassassin/branches/3.1/spamc/utils.c Thu Mar  9 10:54:48 2006
@@ -67,6 +67,33 @@
 }
 #endif
 
+int timeout_connect (int sockfd, const struct sockaddr *serv_addr, size_t addrlen)
+{
+    int ret;
+
+#ifndef _WIN32
+    sigfunc* sig;
+
+    sig = sig_catch(SIGALRM, catch_alrm);
+    if (libspamc_timeout > 0) {
+      alarm(libspamc_timeout);
+    }
+#endif
+
+    ret = connect(sockfd, serv_addr, addrlen);
+
+#ifndef _WIN32
+    if (libspamc_timeout > 0) {
+      alarm(0);
+    }
+  
+    /* restore old signal handler */
+    sig_catch(SIGALRM, sig);
+#endif
+  
+    return ret;
+}
+
 int fd_timeout_read(int fd, char fdflag, void *buf, size_t nbytes)
 {
     int nred;

Modified: spamassassin/branches/3.1/spamc/utils.h
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/spamc/utils.h?rev=384582&r1=384581&r2=384582&view=diff
==============================================================================
--- spamassassin/branches/3.1/spamc/utils.h (original)
+++ spamassassin/branches/3.1/spamc/utils.h Thu Mar  9 10:54:48 2006
@@ -20,6 +20,8 @@
 
 #define UNUSED_VARIABLE(v)	((void)(v))
 
+#include <stddef.h>
+
 extern int libspamc_timeout;	/* default timeout in seconds */
 
 #ifdef SPAMC_SSL
@@ -87,6 +89,9 @@
 
 int fd_timeout_read(int fd, char fdflag, void *, size_t);
 int ssl_timeout_read(SSL * ssl, void *, int);
+
+/* uses size_t instead of socket_t because socket_t not defined on some platforms */
+int timeout_connect (int sockfd, const struct sockaddr *serv_addr, size_t addrlen);
 
 /* these are fd-only, no SSL support */
 int full_read(int fd, char fdflag, void *buf, int min, int len);



Mime
View raw message