testbot: Capture the worker scripts Perl errors in the general log.

Francois Gouget fgouget at codeweavers.com
Tue Dec 11 05:07:45 CST 2012


Also simplify the fork()+exec() code a bit.
---
 testbot/bin/Engine.pl          |   50 ++++++++++++++++++----------------------
 testbot/lib/WineTestBot/Log.pm |   18 +++++++++++++++
 testbot/lib/WineTestBot/VMs.pm |   17 ++++++++------
 3 files changed, 50 insertions(+), 35 deletions(-)

diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index ff1a586..c2c4760 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -120,18 +120,16 @@ sub HandleJobStatusChange
   {
     $ActiveBackEnds{'WineTestBot'}->PrepareForFork();
     my $Pid = fork;
-    if (defined($Pid) && ! $Pid)
+    if (!defined $Pid)
     {
-      exec("$BinDir/${ProjectName}SendLog.pl $JobKey");
+      LogMsg "Unable to fork for ${ProjectName}SendLog.pl: $!\n";
     }
-    if (defined($Pid) && ! $Pid)
+    elsif (!$Pid)
     {
-      LogMsg "Unable to exec ${ProjectName}SendLog.pl : $!\n";
-      exit;
-    }
-    if (! defined($Pid))
-    {
-      LogMsg "Unable to fork for ${ProjectName}SendLog.pl : $!\n";
+      WineTestBot::Log::SetupRedirects();
+      exec("$BinDir/${ProjectName}SendLog.pl $JobKey") or
+      LogMsg "Unable to exec ${ProjectName}SendLog.pl: $!\n";
+      exit(1);
     }
   }
 
@@ -244,18 +242,16 @@ sub CheckForWinetestUpdate
 
   $ActiveBackEnds{'WineTestBot'}->PrepareForFork();
   my $Pid = fork;
-  if (defined($Pid) && ! $Pid)
-  {
-    exec("$BinDir/CheckForWinetestUpdate.pl $Bits");
-  }
-  if (defined($Pid) && ! $Pid)
+  if (!defined $Pid)
   {
-    LogMsg "Unable to exec CheckForWinetestUpdate.pl : $!\n";
-    exit;
+    LogMsg "Unable to fork for CheckForWinetestUpdate.pl: $!\n";
   }
-  if (! defined($Pid))
+  elsif (!$Pid)
   {
-    LogMsg "Unable to fork for CheckForWinetestUpdate.pl : $!\n";
+    WineTestBot::Log::SetupRedirects();
+    exec("$BinDir/CheckForWinetestUpdate.pl $Bits") or
+    LogMsg "Unable to exec CheckForWinetestUpdate.pl: $!\n";
+    exit(1);
   }
 }
 
@@ -395,19 +391,17 @@ sub HandleWinePatchWebNotification
   {
     $ActiveBackEnds{'WineTestBot'}->PrepareForFork();
     my $Pid = fork;
-    if (defined($Pid) && ! $Pid)
+    if (!defined $Pid)
     {
-      exec("$BinDir/WinePatchesWebGet.pl " . ($MaxExistingWebPatchId + 1) .
-           " " . $LatestWebPatchId);
-    }
-    if (defined($Pid) && ! $Pid)
-    {
-      LogMsg "Unable to exec WinePatchesWebGet.pl : $!\n";
-      exit;
+      LogMsg "Unable to fork for WinePatchesWebGet.pl: $!\n";
     }
-    if (! defined($Pid))
+    elsif (!$Pid)
     {
-      LogMsg "Unable to fork for WinePatchesWebGet.pl : $!\n";
+      WineTestBot::Log::SetupRedirects();
+      exec("$BinDir/WinePatchesWebGet.pl " . ($MaxExistingWebPatchId + 1) .
+           " " . $LatestWebPatchId) or
+      LogMsg "Unable to exec WinePatchesWebGet.pl: $!\n";
+      exit(1);
     }
   }
 
diff --git a/testbot/lib/WineTestBot/Log.pm b/testbot/lib/WineTestBot/Log.pm
index 102b74d..6982943 100644
--- a/testbot/lib/WineTestBot/Log.pm
+++ b/testbot/lib/WineTestBot/Log.pm
@@ -57,4 +57,22 @@ sub LogMsg(@)
   print $logfile scalar localtime, " ", $logprefix, ": ", @_ if ($logfile);
 }
 
+sub SetupRedirects()
+{
+  if (defined $logfile)
+  {
+    if (open(STDERR, ">>&", $logfile))
+    {
+      # Make sure stderr still flushes after each print
+      my $tmp=select(STDERR);
+      $| = 1;
+      select($tmp);
+    }
+    else
+    {
+      LogMsg "unable to redirect stderr to the log file\n";
+    }
+  }
+}
+
 1;
diff --git a/testbot/lib/WineTestBot/VMs.pm b/testbot/lib/WineTestBot/VMs.pm
index b7dd486..bcedb15 100644
--- a/testbot/lib/WineTestBot/VMs.pm
+++ b/testbot/lib/WineTestBot/VMs.pm
@@ -530,16 +530,19 @@ sub RunRevert
 
   $self->GetBackEnd()->PrepareForFork();
   my $Pid = fork;
-  if (defined($Pid) && ! $Pid)
+  if (!defined $Pid)
   {
-    $ENV{PATH} = "/usr/bin:/bin";
-    delete $ENV{ENV};
-    exec("$BinDir/RevertVM.pl", $self->GetKey());
-    exit;
+    return "Unable to start child process: $!";
   }
-  if (! defined($Pid))
+  elsif (!$Pid)
   {
-    return "Unable to start child process: $!";
+    $ENV{PATH} = "/usr/bin:/bin";
+    delete $ENV{ENV};
+    WineTestBot::Log::SetupRedirects();
+    exec("$BinDir/RevertVM.pl", $self->GetKey()) or
+    require WineTestBot::Log;
+    WineTestBot::Log::LogMsg "Unable to exec RevertVM.pl: $!\n";
+    exit(1);
   }
 
   return undef;
-- 
1.7.10.4




More information about the wine-patches mailing list