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/11/12 01:28:57 UTC

svn commit: r332684 - /spamassassin/trunk/build/automc/freqsd

Author: jm
Date: Fri Nov 11 16:28:56 2005
New Revision: 332684

URL: http://svn.apache.org/viewcvs?rev=332684&view=rev
Log:
add SIGINT handler, pidfile, and --wake switches

Modified:
    spamassassin/trunk/build/automc/freqsd

Modified: spamassassin/trunk/build/automc/freqsd
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/build/automc/freqsd?rev=332684&r1=332683&r2=332684&view=diff
==============================================================================
--- spamassassin/trunk/build/automc/freqsd (original)
+++ spamassassin/trunk/build/automc/freqsd Fri Nov 11 16:28:56 2005
@@ -2,7 +2,32 @@
 
 use strict;
 use warnings;
-sub run;
+
+use Getopt::Long;
+
+use vars qw(
+    $pidfile
+    $opt_wake
+);
+GetOptions(
+    "pidfile=s" => \$pidfile,
+    "wake" => \$opt_wake,
+);
+
+if ($opt_wake) {
+  die "wake needs pidfile" if (!$pidfile);
+  open(IN, "<$pidfile") or die "cannot read $pidfile";
+  my $pid = <IN> + 0;
+  close IN;
+
+  if ($pid <= 1) {
+    die "pid out of range: $pid";
+  }
+
+  kill (1,$pid) or die "kill -1 $pid failed";
+  print "signalled $pid\n";
+  exit;
+}
 
 # ---------------------------------------------------------------------------
 
@@ -16,6 +41,9 @@
 # the child process generates the slow reports
 my $child_reports = "OVERLAP.new";
 
+# seconds between build-polls
+my $idle_sleep = 30;
+
 # ---------------------------------------------------------------------------
 
 my $am_parent;
@@ -31,7 +59,14 @@
 }
 
 $SIG{HUP} = \&sighup_handler;
-$SIG{TERM} = sub { kill(15, $child_pid); die "terminated"; };
+$SIG{INT} = \&sigterm_handler;
+$SIG{TERM} = \&sigterm_handler;
+
+if ($pidfile) {
+  open(OUT, ">$pidfile") or die "cannot write to $pidfile";
+  print OUT $$;
+  close OUT or die "cannot save $pidfile";
+}
 
 while (1) {
   if ($am_parent) {
@@ -50,7 +85,7 @@
         "--override='output_classes=$parent_reports'");
   print "completed faster reports ($$) at ".(scalar localtime time)."\n";
 
-  sleep 600;        # sleep until timeout, or we get SIGHUPped
+  sleep $idle_sleep;        # sleep until timeout, or we get SIGHUPped
 }
 
 # ---------------------------------------------------------------------------
@@ -61,7 +96,7 @@
         "--override='output_classes=$child_reports'");
   print "completed slow reports ($$) at ".(scalar localtime time)."\n";
 
-  sleep 600;        # sleep until timeout, or we get SIGHUPped
+  sleep $idle_sleep;        # sleep until timeout, or we get SIGHUPped
 }
 
 # ---------------------------------------------------------------------------
@@ -70,6 +105,15 @@
   warn "received SIGHUP at ".(scalar localtime time)."\n";
   # this SIGHUP will interrupt a sleep() if one is in progress
   if ($am_parent) { kill(1, $child_pid); } # pass it on
+}
+
+# ---------------------------------------------------------------------------
+
+sub sigterm_handler {
+  warn "received SIGTERM at ".(scalar localtime time)."\n";
+  kill(15, $child_pid);
+  if ($pidfile) { unlink($pidfile); }
+  die "terminated";
 }