[exim-dev] [PATCH] spam.c small performace and debugging imp…

Top Page
Delete this message
Reply to this message
Author: Jens Taprogge
Date:  
To: Exim Devel List
Subject: [exim-dev] [PATCH] spam.c small performace and debugging improvement
Hello,

attached please find a patch that does the following:
- it eliminates a memset() and replaces it by manually terminating
the string received from spamd.
- it removes a double close(spamd_sock)
- makes most global variables defined in spam.c static
- logs a message in case spamd returns no data.

The last change helped me debug a problem that turned out to be caused
by spamd clients dieing.

Please consider the patch for applying.

Best Regards
Jens Taprogge
--- exim-4.69/src/spam.c    2007-05-14 20:56:25.000000000 +0200
+++ exim-4.69_2/src/spam.c    2008-01-31 20:23:47.000000000 +0100
@@ -15,9 +15,11 @@


-uschar spam_score_buffer[16];
-uschar spam_score_int_buffer[16];
-uschar spam_bar_buffer[128];
-uschar spam_report_buffer[32600];
-uschar prev_user_name[128] = "";
+static uschar spam_score_buffer[16];
+static uschar spam_score_int_buffer[16];
+static uschar spam_bar_buffer[128];
+static uschar spam_report_buffer[32600];
+static uschar prev_user_name[128] = "";
+static int spam_rc = 0;
+
+/* accessed by spool_mbox.c */
int spam_ok = 0;
-int spam_rc = 0;

@@ -208,3 +210,2 @@ int spam(uschar **listptr) {
   if (send(spamd_sock, spamd_buffer, Ustrlen(spamd_buffer), 0) < 0) {
-    (void)close(spamd_sock);
     log_write(0, LOG_MAIN|LOG_PANIC,
@@ -297,3 +298,2 @@ again:
    */
-  memset(spamd_buffer, 0, sizeof(spamd_buffer));
   offset = 0;
@@ -305,2 +305,3 @@ again:
   }
+  *(spamd_buffer + offset) = '\0';


@@ -317,2 +318,11 @@ again:

+  /* Did spamd return any data at all? 
+   * If not it indicates that the client died. */
+  if (offset == 0) {
+    log_write(0, LOG_MAIN|LOG_PANIC,
+    "spam acl condition: spamd closed the connection without returning "
+    "any data.  This is likely caused by the spamd client having died.");
+    return DEFER;
+  }
+
   /* dig in the spamd output and put the report in a multiline header, if requested */