testbot/lib: Tweak Log.pm to not open the log file for every message.

Francois Gouget fgouget at codeweavers.com
Thu Oct 4 07:40:08 CDT 2012


Also issue a meaningful message to stderr if we cannot open the log file.
---

The file descriptor is configured to be flushed after each write 
operation so there should be no problem with concurrency or not closing 
it.

 testbot/lib/WineTestBot/Log.pm |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/testbot/lib/WineTestBot/Log.pm b/testbot/lib/WineTestBot/Log.pm
index a6762cc..6883968 100644
--- a/testbot/lib/WineTestBot/Log.pm
+++ b/testbot/lib/WineTestBot/Log.pm
@@ -32,16 +32,28 @@ require Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(&LogMsg);
 
-sub LogMsg
+my $logfile;
+sub LogMsg(@)
 {
-  my $oldumask = umask(002);
-  my $LOGFILE;
-  if (open LOGFILE, ">>$LogDir/log")
+  if (!defined $logfile)
   {
-    print LOGFILE scalar localtime, " ", @_;
-    close LOGFILE;
+    my $oldumask = umask(002);
+    if (open($logfile, ">>", "$LogDir/log"))
+    {
+      # Flush after each print
+      my $tmp=select($logfile);
+      $| = 1;
+      select($tmp);
+    }
+    else
+    {
+      require File::Basename;
+      print STDERR File::Basename::basename($0), ":warning: could not open '$LogDir/log' for writing: $!\n";
+      $logfile = undef;
+    }
+    umask($oldumask);
   }
-  umask($oldumask);
+  print $logfile scalar localtime, " ", @_ if ($logfile);
 }
 
 1;
-- 
1.7.10.4




More information about the wine-patches mailing list