Skip to content
Snippets Groups Projects
Commit ab637c17 authored by Mark Harrison's avatar Mark Harrison
Browse files

Add locking when reading/writing resmon state.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@368 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 98ad146c
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ sub get_shared_state {
my $self = shift;
my $fh = $self->{shared_state};
if (defined $fh) {
flock($fh, LOCK_EX); # Obtain a lock on the file
my $VAR1;
$fh->seek(0, 0);
my $blob;
......@@ -35,6 +36,7 @@ sub get_shared_state {
local $/ = undef;
$blob = <$fh>;
}
flock($fh, LOCK_UN); # Release the lock
eval $blob;
die $@ if ($@);
$self->{store} = $VAR1;
......@@ -48,10 +50,12 @@ sub store_shared_state {
my $self = shift;
my $fh = $self->{shared_state};
if (defined($fh)) {
flock($fh, LOCK_EX); # Obtain a lock on the file
$fh->truncate(0);
$fh->seek(0,0);
print $fh Dumper($self->{store});
$fh->flush();
flock($fh, LOCK_UN); # Release the lock
} else {
die "Unable to store shared state";
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment