diff options
author | Tobi Oetiker <tobi@oetiker.ch> | 2008-01-21 23:18:48 +0100 |
---|---|---|
committer | Tobi Oetiker <tobi@oetiker.ch> | 2008-01-21 23:18:48 +0100 |
commit | 88c73fdb0c653f6366a06c21aa9c055245b8641a (patch) | |
tree | 84e9c0fe88aa94a291e43831bd4bd603a84e8acc /lib/Smokeping/Master.pm | |
parent | f0d944ab93f7603843ba3a8ec825261d339c7eef (diff) | |
download | smokeping-88c73fdb0c653f6366a06c21aa9c055245b8641a.tar.gz smokeping-88c73fdb0c653f6366a06c21aa9c055245b8641a.tar.xz |
added alternate presentation hierarchies. Configure via Presentation->hierarchies and
Targets ... -> parents -- tobi
Diffstat (limited to 'lib/Smokeping/Master.pm')
-rw-r--r-- | lib/Smokeping/Master.pm | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/Smokeping/Master.pm b/lib/Smokeping/Master.pm index e54a264..4a5cd90 100644 --- a/lib/Smokeping/Master.pm +++ b/lib/Smokeping/Master.pm @@ -1,7 +1,7 @@ # -*- perl -*- package Smokeping::Master; use Data::Dumper; -use Storable qw(nstore_fd dclone fd_retrieve); +use Storable qw(nstore dclone retrieve); use strict; use warnings; use Fcntl qw(:flock); @@ -105,30 +105,27 @@ sub save_updates { " in the local data structure. Make sure you run the ". "smokeping daemon. ($cfg->{General}{datadir})\n"; } - elsif ( open (my $hand, '+>>' , $file) ) { - for (my $i = 10; $i < 0; $i--){ - if ( flock $hand, LOCK_EX ){ + elsif ( open (my $lock, '>>' , "$file.lock") ) { + for (my $i = 10; $i > 0; $i--){ + if ( flock $lock, LOCK_EX ){ my $existing = []; - if ( (stat($hand))[7] > 0 ){ - seek $hand, 0,0; - eval { $existing = fd_retrieve $hand }; + if ( -r $file ){ + my $in = eval { retrieve $file }; if ($@) { #error warn "Loading $file: $@"; - $existing = []; - } + } else { + $existing = $in; + }; }; push @{$existing}, [ $slave, $time, $updatestring]; - seek $hand, 0,0; - truncate $hand, 0; - nstore_fd ($existing, $hand); - flock $hand, LOCK_UN; + nstore($existing, $file); last; } else { warn "Could not lock $file. Trying again for $i rounds.\n"; sleep rand(3); } } - close $hand; + close $lock; } else { warn "Could not update $file: $!"; } @@ -145,20 +142,18 @@ sub get_slaveupdates { my $name = shift; my $file = $name.".slave_cache"; my $data; - if ( open (my $hand, '+<', $file) ) { - if ( flock $hand, LOCK_EX ){ - rename $file,$file.$$; - eval { $data = fd_retrieve $hand }; - unlink $file.$$; - flock $hand, LOCK_UN; + if ( -r $file and open (my $lock, '>>', "$file.lock") ) { + if ( flock $lock, LOCK_EX ){ + eval { $data = retrieve $file }; + unlink $file; if ($@) { #error warn "Loading $file: $@"; - return; + return undef; } } else { warn "Could not lock $file. Will skip and try again in the next round. No harm done!\n"; } - close $hand; + close $lock; return $data; } return; |