introduce another sharedmem variable called startup_time, which is set by zmc indicating when the process started.

pull/1628/head
Isaac Connor 2016-09-15 11:16:05 -04:00
parent 37c559ba3d
commit 8f33ed6ca6
5 changed files with 51 additions and 21 deletions

View File

@ -164,6 +164,7 @@ our $mem_data =
"imagesize" => { "type"=>"uint32", "seq"=>$mem_seq++ },
"epadding1" => { "type"=>"uint32", "seq"=>$mem_seq++ },
"epadding2" => { "type"=>"uint32", "seq"=>$mem_seq++ },
"startup_time" => { "type"=>"time_t64", "seq"=>$mem_seq++ },
"last_write_time" => { "type"=>"time_t64", "seq"=>$mem_seq++ },
"last_read_time" => { "type"=>"time_t64", "seq"=>$mem_seq++ },
"control_state" => { "type"=>"uint8[256]", "seq"=>$mem_seq++ },
@ -614,6 +615,10 @@ sub zmHasAlarmed
return( undef );
}
sub zmGetStartupTime {
return zmMemRead( $_[0], 'shared_data:startup_time' );
}
sub zmGetLastEvent
{
my $monitor = shift;

View File

@ -96,26 +96,33 @@ while( 1 ) {
Debug( "LastWriteTime is not defined." );
next;
}
Debug( "LastWriteTime is = $image_time." );
if ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
Debug( "LastWriteTime is = $image_time." );
my $startup_time = zmGetStartupTime( $monitor );
if ( $now - $startup_time > $max_image_delay ) {
Info( "Restarting capture daemon for ".$monitor->{Name}.", no image since startup. Startup time was $startup_time - now $now > $max_image_delay\n" );
$restart = 1;
} else {
# We can't get the last capture time so can't be sure it's died, it might just be starting up.
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;
}
if ( ! $restart ) {
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;
}
} # end if ! restart
} else {
Info( "Restarting capture daemon for ".$monitor->{Name}.", shared data not valid\n" );
$restart = 1;

View File

@ -128,14 +128,18 @@ class Monitor
** Shared memory layout should be identical for both 32bit and 64bit and is multiples of 16.
*/
union { /* +64 */
time_t last_write_time;
time_t startup_time; /* When the zmc process started. zmwatch uses this to see how long the process has been running without getting any images */
uint64_t extrapad1;
};
union { /* +72 */
time_t last_read_time;
union { /* +72 */
time_t last_write_time;
uint64_t extrapad2;
};
uint8_t control_state[256]; /* +80 */
union { /* +80 */
time_t last_read_time;
uint64_t extrapad3;
};
uint8_t control_state[256]; /* +88 */
} SharedData;
@ -216,6 +220,12 @@ class Monitor
inline time_t getLastConnectTime() const {
return( last_connect_time );
}
inline time_t getStartupTime() const {
return( shared_data->startup_time );
}
inline void setStartupTime( time_t p_time ) {
shared_data->startup_time = p_time;
}
bool connect();
bool disconnect();

View File

@ -310,6 +310,7 @@ int RemoteCameraHttp::GetResponse()
static RegExpr *content_type_expr = 0;
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
Debug(4, "Timeout waiting for REGEXP HEADER");
}
if ( buffer_len < 0 ) {
Error( "Unable to read header data" );
@ -483,6 +484,7 @@ int RemoteCameraHttp::GetResponse()
{
Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
Debug(4, "Timeout waiting to extract subheader");
}
if ( buffer_len < 0 ) {
Error( "Unable to extract subheader data" );
@ -535,6 +537,7 @@ int RemoteCameraHttp::GetResponse()
while ( !content_length )
{
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
Debug(4, "Timeout waiting for content");
}
if ( buffer_len < 0 ) {
Error( "Unable to read content" );
@ -660,6 +663,7 @@ int RemoteCameraHttp::GetResponse()
case HEADERCONT :
{
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
Debug(4, "Timeout waiting for HEADERCONT");
}
if ( buffer_len < 0 ) {
Error( "Unable to read header" );
@ -1009,6 +1013,7 @@ int RemoteCameraHttp::GetResponse()
{
Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) {
Debug(4, "Timeout waiting to extra subheader non regexp");
}
if ( buffer_len < 0 ) {
Error( "Unable to read subheader" );
@ -1059,6 +1064,7 @@ int RemoteCameraHttp::GetResponse()
while ( (long)buffer.size() < content_length )
{
//int buffer_len = ReadData( buffer, content_length-buffer.size() );
Debug(4, "getting mroe data");
if ( ReadData( buffer ) < 0 ) {
Error( "Unable to read content" );
return( -1 );
@ -1071,6 +1077,7 @@ int RemoteCameraHttp::GetResponse()
int content_pos = 0;
while ( !content_length )
{
Debug(4, "!content_length, ReadData");
buffer_len = ReadData( buffer );
if ( buffer_len < 0 )
{

View File

@ -258,6 +258,7 @@ int main( int argc, char *argv[] )
sigaddset( &block_set, SIGUSR1 );
sigaddset( &block_set, SIGUSR2 );
monitors[0]->setStartTime( time(NULL) );
if ( monitors[0]->PrimeCapture() < 0 )
{
Error( "Failed to prime capture of initial monitor" );