aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2012-03-12 18:13:49 +0000
committerPascal Terjan <pterjan@mageia.org>2012-03-12 18:13:49 +0000
commit795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5 (patch)
tree07fbce00ef834904a381d00ca62e6d739743efc9
parent8d9f708ca0b3613a99a2b85f25ef6fad76f16b02 (diff)
downloadiurt-795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5.tar
iurt-795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5.tar.gz
iurt-795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5.tar.bz2
iurt-795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5.tar.xz
iurt-795d8a847ba15ee5d5d8fd1eda8742e41b4d90e5.zip
Lock the log file when writing
This allows using a shared logfile
-rw-r--r--lib/Iurt/Util.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Iurt/Util.pm b/lib/Iurt/Util.pm
index 8a06584..47a197b 100644
--- a/lib/Iurt/Util.pm
+++ b/lib/Iurt/Util.pm
@@ -1,6 +1,7 @@
package Iurt::Util;
use base qw(Exporter);
+use Fcntl qw(:flock SEEK_END);
use strict;
our @EXPORT = qw(
@@ -108,7 +109,12 @@ sub plog {
$level = $plog_level{$level};
my ($p, $e) = ($plog_prefix[$level], ($plog_color ? $plog_ctr{normal} : ""));
- print $plog_file "$p@_$e\n" if $plog_level >= $level;
+ if ($plog_level >= $level) {
+ flock($plog_file, LOCK_EX);
+ seek($plog_file, 0, SEEK_END);
+ print $plog_file "$p@_$e\n";
+ flock($plog_file, LOCK_UN);
+ }
}
sub pdie {