Changeset ab637c1792a4b0a60d352968204b4b73999f7d99

Show
Ignore:
Timestamp:
05/12/10 15:19:19 (4 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1273677559 +0000
git-parent:

[98ad146c9d9c3d428099a83049740040d32dc48a]

git-author:
Mark Harrison <mark@omniti.com> 1273677559 +0000
Message:

Add locking when reading/writing resmon state.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@368 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Status.pm

    r98ad146 rab637c1  
    2929    my $fh = $self->{shared_state}; 
    3030    if (defined $fh) { 
     31        flock($fh, LOCK_EX); # Obtain a lock on the file 
    3132        my $VAR1; 
    3233        $fh->seek(0, 0); 
     
    3637            $blob = <$fh>; 
    3738        } 
     39        flock($fh, LOCK_UN); # Release the lock 
    3840        eval $blob; 
    3941        die $@ if ($@); 
     
    4951    my $fh = $self->{shared_state}; 
    5052    if (defined($fh)) { 
     53        flock($fh, LOCK_EX); # Obtain a lock on the file 
    5154        $fh->truncate(0); 
    5255        $fh->seek(0,0); 
    5356        print $fh Dumper($self->{store}); 
    5457        $fh->flush(); 
     58        flock($fh, LOCK_UN); # Release the lock 
    5559    } else { 
    5660        die "Unable to store shared state";