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 2005/08/20 05:03:34 UTC

svn commit: r233990 - in /spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin: DCC.pm Pyzor.pm

Author: jm
Date: Fri Aug 19 20:03:32 2005
New Revision: 233990

URL: http://svn.apache.org/viewcvs?rev=233990&view=rev
Log:
bug 4518: fix situation where helper apps can be left running after SA times out on them, thanks to Mark Martinec

Modified:
    spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/DCC.pm
    spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/Pyzor.pm

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/DCC.pm
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/DCC.pm?rev=233990&r1=233989&r2=233990&view=diff
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/DCC.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/DCC.pm Fri Aug 19 20:03:32 2005
@@ -457,6 +457,7 @@
   my $tmpf = $permsgstatus->create_fulltext_tmpfile($fulltext);
   my $oldalarm = 0;
 
+  my $pid;
   eval {
     # safe to use $SIG{ALRM} here instead of Util::trap_sigalrm_fully(),
     # since there are no killer regexp hang dangers here
@@ -472,12 +473,13 @@
 
     dbg("dcc: opening pipe: " . join(' ', $path, "-H", $opts, "< $tmpf"));
 
-    my $pid = Mail::SpamAssassin::Util::helper_app_pipe_open(*DCC,
+    $pid = Mail::SpamAssassin::Util::helper_app_pipe_open(*DCC,
 	$tmpf, 1, $path, "-H", split(' ', $opts));
     $pid or die "$!\n";
 
     my @null = <DCC>;
-    close DCC;
+    close DCC
+      or dbg(sprintf("dcc: [%s] finished: %s exit=0x%04x",$pid,$!,$?));
 
     if (!@null) {
       # no facility prefix on this
@@ -508,6 +510,14 @@
   # do NOT reinstate $oldalarm here; we may already have done that in
   # the success case.  leave it to the error handler below
   my $err = $@;
+  if (defined(fileno(*DCC))) {  # still open
+    if ($pid) {
+      if (kill('TERM',$pid)) { dbg("dcc: killed stale helper [$pid]") }
+      else { dbg("dcc: killing helper application [$pid] failed: $!") }
+    }
+    close DCC
+      or dbg(sprintf("dcc: [%s] terminated: %s exit=0x%04x",$pid,$!,$?));
+  }
   $permsgstatus->leave_helper_run_mode();
 
   if ($err) {

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/Pyzor.pm
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/Pyzor.pm?rev=233990&r1=233989&r2=233990&view=diff
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/Pyzor.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/Plugin/Pyzor.pm Fri Aug 19 20:03:32 2005
@@ -224,6 +224,7 @@
   my $tmpf = $permsgstatus->create_fulltext_tmpfile($fulltext);
   my $oldalarm = 0;
 
+  my $pid;
   eval {
     # safe to use $SIG{ALRM} here instead of Util::trap_sigalrm_fully(),
     # since there are no killer regexp hang dangers here
@@ -239,12 +240,13 @@
  
     dbg("pyzor: opening pipe: " . join(' ', $path, $opts, "check", "< $tmpf"));
 
-    my $pid = Mail::SpamAssassin::Util::helper_app_pipe_open(*PYZOR,
+    $pid = Mail::SpamAssassin::Util::helper_app_pipe_open(*PYZOR,
 	$tmpf, 1, $path, split(' ', $opts), "check");
     $pid or die "$!\n";
 
     @response = <PYZOR>;
-    close PYZOR;
+    close PYZOR
+      or dbg(sprintf("pyzor: [%s] finished: %s exit=0x%04x",$pid,$!,$?));
 
     if (!@response) {
       # this exact string is needed below
@@ -266,6 +268,14 @@
   # do NOT reinstate $oldalarm here; we may already have done that in
   # the success case.  leave it to the error handler below
   my $err = $@;
+  if (defined(fileno(*PYZOR))) {  # still open
+    if ($pid) {
+      if (kill('TERM',$pid)) { dbg("pyzor: killed stale helper [$pid]") }
+      else { dbg("pyzor: killing helper application [$pid] failed: $!") }
+    }
+    close PYZOR
+      or dbg(sprintf("pyzor: [%s] terminated: %s exit=0x%04x",$pid,$!,$?));
+  }
   $permsgstatus->leave_helper_run_mode();
 
   if ($err) {