From: martinahansen Date: Wed, 10 Oct 2012 12:49:35 +0000 (+0000) Subject: added some file locking to Biopieces.pm X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=255bd12a360f04cf2de491c827b69281f4bf278d;p=biopieces.git added some file locking to Biopieces.pm git-svn-id: http://biopieces.googlecode.com/svn/trunk@1961 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 67d3bd9..1d1ef65 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -70,6 +70,7 @@ sub status_set $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; $fh = Maasha::Filesys::file_write_open( $file ); + flock($fh, 2); print $fh join( ";", $time_stamp, join( " ", @ARGV ) ) . "\n"; @@ -103,6 +104,7 @@ sub status_log return if not -f $file; $fh = Maasha::Filesys::file_read_open( $file ); + flock($fh, 1); $line = <$fh>; chomp $line; close $fh; @@ -116,7 +118,9 @@ sub status_log $elap = Maasha::Common::time_stamp_diff( $time0, $time1 ); $fh_global = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" ); + flock($fh_global, 2); $fh_local = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" ); + flock($fh_local, 2); print $fh_global join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n"; print $fh_local join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n"; @@ -144,6 +148,7 @@ sub log_biopiece $script = Maasha::Common::get_scriptname(); $fh = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" ); + flock($fh, 2); print $fh "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n"; @@ -836,11 +841,13 @@ sub get_tmpdir $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; $fh = Maasha::Filesys::file_read_open( $file ); + flock($fh, 1); $line = <$fh>; chomp $line; close $fh; $fh = Maasha::Filesys::file_write_open( $file ); + flock($fh, 2); print $fh "$line;$path\n"; close $fh; @@ -869,6 +876,7 @@ sub biopiecesrc return undef if not -f $file; $fh = Maasha::Filesys::file_read_open( $file ); + flock($fh, 1); $record = get_record( $fh ); close $fh;