summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNiko Tyni <ntyni@iki.fi>2008-03-19 13:57:03 +0100
committerNiko Tyni <ntyni@iki.fi>2008-03-19 13:57:03 +0100
commitbac48a06638f1e8dfdc23980c3cea2fa30ae16e8 (patch)
tree61a080d046e7de15eeff2fa145fe4eb2820d7e22 /lib
parent2944cb07be67d87e1a93ca6abf058dd6ce23d276 (diff)
downloadsmokeping-bac48a06638f1e8dfdc23980c3cea2fa30ae16e8.tar.gz
smokeping-bac48a06638f1e8dfdc23980c3cea2fa30ae16e8.tar.xz
revisit the locking error paths a bit
Diffstat (limited to 'lib')
-rw-r--r--lib/Smokeping/Master.pm15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Smokeping/Master.pm b/lib/Smokeping/Master.pm
index 7114b00..f8704a0 100644
--- a/lib/Smokeping/Master.pm
+++ b/lib/Smokeping/Master.pm
@@ -120,11 +120,15 @@ sub save_updates {
}
else {
- for (my $i = 3; $i > 0; $i--){
+ for (my $i = 2; $i >= 0; $i--){
my $fh;
if ( open ($fh, '+>>' , $file) and flock($fh, LOCK_EX) ){
my $existing = [];
- next if ! -e $file; # the reader unlinked it from under us
+ if (! -e $file) { # the reader unlinked it from under us
+ flock($fh, LOCK_UN);
+ close $fh;
+ next;
+ }
seek $fh, 0, 0;
if ( -s _ ){
my $in = eval { fd_retrieve $fh };
@@ -139,9 +143,11 @@ sub save_updates {
flock($fh, LOCK_UN);
close $fh;
last;
- } else {
- warn "Could not lock $file ($!). Trying again for $i rounds.\n";
+ } elsif ($i > 0) {
+ warn "Could not lock $file ($!). Trying again $i more times.\n";
+ close $fh;
sleep rand(2);
+ next;
}
warn "Could not update $file, giving up for now.";
close $fh;
@@ -176,6 +182,7 @@ sub get_slaveupdates {
flock $fh, LOCK_UN;
if ($@) { #error
warn "Loading $file: $@";
+ close $fh;
return $empty;
}
} else {