diff --git a/src/zma.cpp b/src/zma.cpp index 7121c99ce..399ea1edc 100644 --- a/src/zma.cpp +++ b/src/zma.cpp @@ -4,9 +4,16 @@ bool reload = false; void hup_handler( int signal ) { + Info(( "Got HUP signal, reloading" )); reload = true; } +void term_handler( int signal ) +{ + Info(( "Got TERM signal, exiting" )); + exit( 0 ); +} + void main( int argc, const char *argv[] ) { int device = argv[1]?atoi( argv[1] ):0; @@ -44,14 +51,27 @@ void main( int argc, const char *argv[] ) action.sa_mask = block_set; action.sa_flags = 0; sigaction( SIGHUP, &action, &old_action ); + action.sa_handler = term_handler; + action.sa_mask = block_set; + action.sa_flags = 0; + sigaction( SIGTERM, &action, &old_action ); sigaddset( &block_set, SIGHUP ); + sigaddset( &block_set, SIGTERM ); while( 1 ) { // Process the next image + bool result = false; sigprocmask( SIG_BLOCK, &block_set, 0 ); for ( int i = 0; i < n_monitors; i++ ) { - monitors[i]->Analyse(); + if ( monitors[i]->Analyse() ) + { + result = true; + } + } + if ( !result ) + { + usleep( 10000 ); } sigprocmask( SIG_UNBLOCK, &block_set, 0 ); if ( reload ) diff --git a/src/zmc.cpp b/src/zmc.cpp index 6a3132590..fe45f4f1c 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -4,9 +4,16 @@ bool reload = false; void hup_handler( int signal ) { + Info(( "Got HUP signal, reloading" )); reload = true; } +void term_handler( int signal ) +{ + Info(( "Got TERM signal, exiting" )); + exit( 0 ); +} + void main( int argc, const char *argv[] ) { int device = argv[1]?atoi( argv[1] ):0; @@ -44,7 +51,12 @@ void main( int argc, const char *argv[] ) action.sa_mask = block_set; action.sa_flags = 0; sigaction( SIGHUP, &action, &old_action ); + action.sa_handler = term_handler; + action.sa_mask = block_set; + action.sa_flags = 0; + sigaction( SIGTERM, &action, &old_action ); sigaddset( &block_set, SIGHUP ); + sigaddset( &block_set, SIGTERM ); if ( n_monitors == 1 ) { monitors[0]->PreCapture(); @@ -63,8 +75,10 @@ void main( int argc, const char *argv[] ) { for ( int i = 0; i < n_monitors; i++ ) { - monitors[i]->CheckFunction(); + delete monitors[i]; } + monitors = 0; + n_monitors = Monitor::Load( device, monitors ); reload = false; } }