diff -ur MailScanner-4.30.3/bin/MailScanner MailScanner-4.30.3-fg/bin/MailScanner
--- MailScanner-4.30.3/bin/MailScanner	Sun May  2 14:33:43 2004
+++ MailScanner-4.30.3-fg/bin/MailScanner	Sun May 30 16:58:51 2004
@@ -186,6 +186,8 @@
 #
 my $MaxChildren = MailScanner::Config::QuickPeek($ConfFile, 'maxchildren');
 my $Debug       = MailScanner::Config::QuickPeek($ConfFile, 'debug');
+use vars qw($RunInForeground);
+$RunInForeground = MailScanner::Config::QuickPeek($ConfFile, 'runinforeground');
 my $WorkDir     = MailScanner::Config::QuickPeek($ConfFile, 'incomingworkdir');
 my $BayesRebuildPeriod = MailScanner::Config::QuickPeek($ConfFile, 'rebuildbayesevery');
 # FIXME: we should check that the ownership and modes on piddir do not
@@ -193,6 +195,11 @@
 # to critical system files, or create pidfiles that point to critical
 # system processes)
 $Debug = 0 unless $Debug =~ /yes|1/i;
+$RunInForeground = 0 unless $RunInForeground =~ /yes|1/i;
+
+# enable STDOUT flushing if running in foreground
+# to be able to actively capture it with a logger
+$| = 1 if $RunInForeground;
 
 # Give the user their shell back
 ForkDaemon($Debug);
@@ -223,6 +230,14 @@
 # Set when the next rebuild is due if regular rebuilds are being done
 $NextRebuildDueTime = time + $BayesRebuildPeriod if $BayesRebuildPeriod;
 
+if ($RunInForeground) {
+  # If we run in foreground, SIGKILL
+  # to the parent will try to reload
+  # by SIGKILLing its children
+  $SIG{'HUP'} = 'ReloadParent';
+}
+
+
 for (;;) {
   while($NumberOfChildren < $MaxChildren) {
     # Trigger 1 Bayes rebuild if the period has expired
@@ -231,6 +246,9 @@
       $RebuildDue = 1;
       $NextRebuildDueTime = time + $BayesRebuildPeriod;
     }
+    if ($RunInForeground) {
+      print STDOUT sprintf ("About to fork child #%d of %d...\n", $NumberOfChildren+1, $MaxChildren);
+    }
     my $born_pid = fork();
     if (!defined($born_pid)) {
       die "Cannot fork off child process, $!";
@@ -242,6 +260,9 @@
       WorkForHours($RebuildDue);
       exit 0;
     }
+    if ($RunInForeground) {
+      print STDOUT "\tforked OK - new kid is [$born_pid]\n"
+    }
     # I am the parent process.
     $Children{$born_pid} = 1;
     $NumberOfChildren++;
@@ -562,28 +583,67 @@
   exit 0;
 }
 
-
-#
-# SIGTERM handler for parent process.
-# HUP all the children, then commit suicide.
-# Cannot log as no logging in the parent.
-#
-sub ExitParent {
-  my($sig) = @_; # Arg is the signal name
+sub KillChildren {
   my($child, @dirlist);
-
   #print STDERR "Killing child processes...\n";
+  if ($RunInForeground) {
+    print STDOUT "Killing child processes ";
+    print STDOUT join( '/', keys %Children);
+  }
   kill 1, keys %Children;
+  if ($RunInForeground) {
+    print STDOUT " and giving them time to die...\n";
+  }
   sleep 3; # Give them time to die peacefully
 
+  if ($RunInForeground) {
+    print STDOUT "Cleaning up...";
+  }
   # Clean up after the dying processes in case they left a mess.
   foreach $child (keys %Children) {
     #push @dirlist, "$WorkDir/$child" if -d "$WorkDir/$child";
     rmtree("$WorkDir/$child", 0, 1) if -d "$WorkDir/$child";
   }
+  if ($RunInForeground) {
+    print STDOUT "Done\n";
+  }
+
+}
+
+
+#
+# SIGKILL handler for parent process.
+# HUP all the children, then keep working.
+#
+sub ReloadParent {
+  my($sig) = @_; # Arg is the signal name
+  if ($RunInForeground) {
+    print STDOUT "MailScanner parent caught a SIG$sig - reload\n";
+  }
 
-  #system($global::rm . " -rf \"" . join("\" \"", @dirlist) . "\"")
-  #  if @dirlist;
+  KillChildren();
+
+  if ($RunInForeground) {
+    print STDOUT "MailScanner reloaded\n";
+  }
+}
+
+#
+# SIGTERM handler for parent process.
+# HUP all the children, then commit suicide.
+# Cannot log as no logging in the parent.
+#
+sub ExitParent {
+  my($sig) = @_; # Arg is the signal name
+  if ($RunInForeground) {
+    print STDOUT "MailScanner parent caught a SIG$sig";
+  }
+
+  KillChildren();
+
+  if ($RunInForeground) {
+    print STDOUT "Exiting MailScanner - Bye\n";
+  }
 
   exit 0;
 }
@@ -630,6 +690,10 @@
     # Get current debugging flag, and invert it:
     my $current = config MIME::ToolUtils 'DEBUGGING';
     #config MIME::ToolUtils DEBUGGING => !$current;
+  } elsif ($RunInForeground) {
+    # PERT-BBY we don't close STDXX neither fork() nor setsid()
+    #          if we want to run in the foreground
+    print STDOUT "MailScanner $MailScanner::Config::MailScannerVersion starting in foreground mode - pid is [$$]\n";
   } else {
     $SIG{'CHLD'} = \&Reaper;
     if (fork==0) {
diff -ur MailScanner-4.30.3/etc/MailScanner.conf MailScanner-4.30.3-fg/etc/MailScanner.conf
--- MailScanner-4.30.3/etc/MailScanner.conf	Sun Apr 25 11:23:43 2004
+++ MailScanner-4.30.3-fg/etc/MailScanner.conf	Fri May 28 18:25:15 2004
@@ -1453,6 +1453,12 @@
 # This value *cannot* be the filename of a ruleset.
 Use Default Rules With Multiple Recipients = no
 
+# Set Run In Foreground to "yes" if you want MailScanner to operate
+# normally in foreground (and not as a background daemon).
+# Use this if you are controlling the execution of MailScanner
+# with a tool like DJB's 'supervise' (see http://cr.yp.to/daemontools.html)
+Run In Foreground = no
+
 # Set Debug to "yes" to stop it running as a daemon and just process
 # one batch of messages and then exit.
 Debug = no
diff -ur MailScanner-4.30.3/lib/MailScanner/ConfigDefs.pl MailScanner-4.30.3-fg/lib/MailScanner/ConfigDefs.pl
--- MailScanner-4.30.3/lib/MailScanner/ConfigDefs.pl	Sun Apr 25 11:23:42 2004
+++ MailScanner-4.30.3-fg/lib/MailScanner/ConfigDefs.pl	Fri May 28 17:16:36 2004
@@ -179,6 +179,7 @@
 #
 [Simple,YesNo]
 bayeswait		0	no	0	yes	1
+runinforeground		0	no	0	yes	1
 debug			0	no	0	yes	1
 debugspamassassin	0	no	0	yes	1
 deliverinbackground	1	no	0	yes	1
