$SIG{ 'TERM' } = \&sig_handler;
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
sub status_set
{
my ( $time_stamp, $script, $user, $pid, $file, $fh );
$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";
return if not -f $file;
$fh = Maasha::Filesys::file_read_open( $file );
+ flock($fh, 1);
$line = <$fh>;
chomp $line;
close $fh;
$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";
# Returns nothing.
- my ( $time_stamp, $user, $script, $fh_global, $fh_local );
+ my ( $time_stamp, $user, $script, $fh );
$time_stamp = Maasha::Common::time_stamp();
$user = Maasha::Common::get_user();
$script = Maasha::Common::get_scriptname();
- $fh_global = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" );
- $fh_local = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" );
+ $fh = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" );
+ flock($fh, 2);
- print $fh_global "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
- print $fh_local "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
+ print $fh "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
- $fh_global->autoflush( 1 );
- $fh_local->autoflush( 1 );
+ $fh->autoflush( 1 );
- close $fh_global;
- close $fh_local;
+ close $fh;
}
# Returns nothing.
- my ( $script, $wiki );
+ my ( %options, $help, $script, $wiki );
+
+ %options = %{ $options };
+ $help = $options{ 'help' };
+ delete $options{ 'help' };
$script = Maasha::Common::get_scriptname();
if ( $script ne 'print_wiki' )
{
- if ( exists $options->{ 'help' } or -t STDIN )
+ if ( $help or -t STDIN )
{
- if ( not ( exists $options->{ 'stream_in' } or $options->{ 'data_in' } ) )
+ if ( not ( exists $options{ 'stream_in' } or $options{ 'data_in' } ) )
{
- if ( scalar keys %{ $options } <= 1 )
+ if ( scalar keys %options == 0 )
{
$wiki = $ENV{ 'BP_DIR' } . "/bp_usage/$script.wiki";
- if ( exists $options->{ 'help' } ) {
+ if ( $help ) {
`print_wiki --data_in=$wiki --help`;
} elsif ( $script =~ /^(list_biopieces|list_genomes|list_mysql_databases|biostat)$/ ) {
return;
elsif ( $sig eq "INT" )
{
print STDERR "\nProgram '$script' interrupted (ctrl-c was pressed)" . " - Please wait for temporary data to be removed\n";
- status_log( "INTERUPTED" );
+ status_log( "INTERRUPTED" );
}
elsif ( $sig eq "TERM" )
{
$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;
return undef if not -f $file;
$fh = Maasha::Filesys::file_read_open( $file );
+ flock($fh, 1);
$record = get_record( $fh );
close $fh;