google code style

This commit is contained in:
Isaac Connor 2016-08-22 11:41:26 -04:00
parent d6b126fe8c
commit 707694d4ea
1 changed files with 91 additions and 101 deletions

View File

@ -78,111 +78,101 @@ my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'S
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
while( 1 )
{
my $now = time();
my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () )
or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
while( 1 ) {
my $now = time();
my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () )
or Fatal( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() ) {
next if $monitor->{Function} eq 'None';
my $restart = 0;
if ( zmMemVerify( $monitor )
&& zmMemRead( $monitor, "shared_data:valid" )
)
{
next if $monitor->{Function} eq 'None';
my $restart = 0;
if ( zmMemVerify( $monitor )
&& zmMemRead( $monitor, "shared_data:valid" )
)
{
# Check we have got an image recently
my $image_time = zmGetLastWriteTime( $monitor );
if ( !defined($image_time) ) {
# Can't read from shared data
Debug( "LastWriteTime is not defined." );
next;
}
if ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
Debug( "LastWriteTime is = $image_time." );
next;
}
# Check we have got an image recently
my $image_time = zmGetLastWriteTime( $monitor );
if ( !defined($image_time) ) {
# Can't read from shared data
Debug( "LastWriteTime is not defined." );
next;
}
if ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
Debug( "LastWriteTime is = $image_time." );
next;
}
my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
;
my $image_delay = $now-$image_time;
Debug( "Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay\n" );
if ( $image_delay > $max_image_delay )
{
Info( "Restarting capture daemon for "
.$monitor->{Name}.", time since last capture $image_delay seconds ($now-$image_time)\n"
);
$restart = 1;
}
}
else
{
Info( "Restarting capture daemon for ".$monitor->{Name}.", shared data not valid\n" );
$restart = 1;
my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
;
my $image_delay = $now-$image_time;
Debug( "Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay\n" );
if ( $image_delay > $max_image_delay ) {
Info( "Restarting capture daemon for "
.$monitor->{Name}.", time since last capture $image_delay seconds ($now-$image_time)\n"
);
$restart = 1;
}
} else {
Info( "Restarting capture daemon for ".$monitor->{Name}.", shared data not valid\n" );
$restart = 1;
}
if ( $restart ) {
my $command;
if ( $monitor->{Type} eq 'Local' ) {
$command = "zmdc.pl restart zmc -d $monitor->{Device}";
} else {
$command = "zmdc.pl restart zmc -m $monitor->{Id}";
}
runCommand( $command );
} elsif ( $monitor->{Function} ne 'Monitor' ) {
# Now check analysis daemon
$restart = 0;
# Check we have got an image recently
my $image_time = zmGetLastReadTime( $monitor );
if ( !defined($image_time) ) {
# Can't read from shared data
$restart = 1;
Error( "Error reading shared data for $$monitor{id} $$monitor{Name}\n");
} elsif ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
$restart = 1;
Error( "Error getting last capture time for $$monitor{id} $$monitor{Name}\n");
} else {
my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
;
my $image_delay = $now-$image_time;
Debug( "Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay\n" );
if ( $image_delay > $max_image_delay ) {
Info( "Analysis daemon for $$monitor{id} $$monitor{Name} needs restarting,"
." time since last analysis $image_delay seconds ($now-$image_time)\n"
);
$restart = 1;
}
}
if ( $restart )
{
my $command;
if ( $monitor->{Type} eq 'Local' )
{
$command = "zmdc.pl restart zmc -d $monitor->{Device}";
}
else
{
$command = "zmdc.pl restart zmc -m $monitor->{Id}";
}
runCommand( $command );
}
elsif ( $monitor->{Function} ne 'Monitor' )
{
# Now check analysis daemon
$restart = 0;
# Check we have got an image recently
my $image_time = zmGetLastReadTime( $monitor );
if ( !defined($image_time) ) {
# Can't read from shared data
$restart = 1;
Error( "Error reading shared data for $$monitor{id} $$monitor{Name}\n");
} elsif ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
$restart = 1;
Error( "Error getting last capture time for $$monitor{id} $$monitor{Name}\n");
} else {
my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
;
my $image_delay = $now-$image_time;
Debug( "Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay\n" );
if ( $image_delay > $max_image_delay )
{
Info( "Analysis daemon for $$monitor{id} $$monitor{Name} needs restarting,"
." time since last analysis $image_delay seconds ($now-$image_time)\n"
);
$restart = 1;
}
}
if ( $restart )
{
Info( "Restarting analysis daemon for $$monitor{id} $$monitor{Name}\n");
my $command = "zmdc.pl restart zma -m ".$monitor->{Id};
runCommand( $command );
} # end if restart
} # end if check analysis daemon
# Prevent open handles building up if we have connect to shared memory
zmMemInvalidate( $monitor );
} # end foreach monitor
sleep( $Config{ZM_WATCH_CHECK_INTERVAL} );
if ( $restart ) {
Info( "Restarting analysis daemon for $$monitor{id} $$monitor{Name}\n");
my $command = "zmdc.pl restart zma -m ".$monitor->{Id};
runCommand( $command );
} # end if restart
} # end if check analysis daemon
# Prevent open handles building up if we have connect to shared memory
zmMemInvalidate( $monitor );
} # end foreach monitor
sleep( $Config{ZM_WATCH_CHECK_INTERVAL} );
} # end while (1)
Info( "Watchdog exiting\n" );
exit();
1;
__END__