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/12/21 10:53:25 UTC

svn commit: r606149 - /spamassassin/branches/3.2/spamassassin.raw

Author: jm
Date: Fri Dec 21 01:53:24 2007
New Revision: 606149

URL: http://svn.apache.org/viewvc?rev=606149&view=rev
Log:
bug 5626: in the 'spamassassin' script, install a signal handler for SIGHUP, SIGINT, SIGTERM and SIGPIPE to ensure that temporary files are removed

Modified:
    spamassassin/branches/3.2/spamassassin.raw

Modified: spamassassin/branches/3.2/spamassassin.raw
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamassassin.raw?rev=606149&r1=606148&r2=606149&view=diff
==============================================================================
--- spamassassin/branches/3.2/spamassassin.raw (original)
+++ spamassassin/branches/3.2/spamassassin.raw Fri Dec 21 01:53:24 2007
@@ -348,6 +348,8 @@
 
 ###########################################################################
 
+setup_sig_handlers();
+
 # Everything below here needs ArchiveIterator ...
 my $iter = new Mail::SpamAssassin::ArchiveIterator(
   {
@@ -408,10 +410,12 @@
 
 ###########################################################################
 
+my $mail;       # global, so signal handler can clean it up; bug 5626
+
 # make sure it only returns false values so that result_sub() isn't called...
 sub wanted {
   my $dataref = $_[3];
-  my $mail    = $spamtest->parse($dataref);
+  $mail       = $spamtest->parse($dataref);
   $count++;
 
   # This is a short cut -- doing white/black-list?  Do it and return quickly.
@@ -430,6 +434,7 @@
     }
 
     $mail->finish();
+    $mail = undef;
     return 1;
   }
 
@@ -440,6 +445,7 @@
     if ( !$opt{'test-mode'} ) {
       print $spamtest->remove_spamassassin_markup ($mail);
       $mail->finish();
+      $mail = undef;
       return 1;
     }
     else {
@@ -450,6 +456,7 @@
       #
       my $new_mail =
         $spamtest->parse( $spamtest->remove_spamassassin_markup($mail) );
+
       $mail->finish();
       $mail = $new_mail;
     }
@@ -462,13 +469,14 @@
     my $new_mail =
       $spamtest->parse( $spamtest->remove_spamassassin_markup($mail) );
     $mail->finish();
+    $mail = $new_mail;
 
     my $failed;
-    if ( $opt{'report'} && !$spamtest->report_as_spam($new_mail) ) {
+    if ( $opt{'report'} && !$spamtest->report_as_spam($mail) ) {
       $failed = 'report';
     }
 
-    if ( $opt{'revoke'} && !$spamtest->revoke_as_spam($new_mail) ) {
+    if ( $opt{'revoke'} && !$spamtest->revoke_as_spam($mail) ) {
       $failed = 'revoke';
     }
 
@@ -477,7 +485,8 @@
       warn "spamassassin: for more information, re-run with -D option to see debug output\n";
     }
 
-    $new_mail->finish();
+    $mail->finish();
+    $mail = undef;
     return 1;
   }
 
@@ -498,9 +507,30 @@
 
   # clean up after ourselves
   $mail->finish();
+  $mail = undef;
+
   $status->finish();
 
   return 1;
+}
+
+###########################################################################
+
+sub setup_sig_handlers {
+  $SIG{HUP}  = \&kill_handler;
+  $SIG{INT}  = \&kill_handler;
+  $SIG{TERM} = \&kill_handler;
+  $SIG{PIPE} = \&kill_handler;
+}
+
+sub kill_handler {
+  my ($sig) = @_;
+  warn "spamassassin: killed by SIG$sig\n";
+  if ($mail) {
+    $mail->finish();      # bug 5626: remove temp files etc.
+    $mail = undef;
+  }
+  exit 0;
 }
 
 # ---------------------------------------------------------------------------