Added terminal signal handler.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@26 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2002-09-23 10:11:04 +00:00
parent 35407be9c4
commit 6ee0d8bdd0
2 changed files with 36 additions and 2 deletions

View File

@ -4,9 +4,16 @@ bool reload = false;
void hup_handler( int signal ) void hup_handler( int signal )
{ {
Info(( "Got HUP signal, reloading" ));
reload = true; reload = true;
} }
void term_handler( int signal )
{
Info(( "Got TERM signal, exiting" ));
exit( 0 );
}
void main( int argc, const char *argv[] ) void main( int argc, const char *argv[] )
{ {
int device = argv[1]?atoi( argv[1] ):0; 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_mask = block_set;
action.sa_flags = 0; action.sa_flags = 0;
sigaction( SIGHUP, &action, &old_action ); 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, SIGHUP );
sigaddset( &block_set, SIGTERM );
while( 1 ) while( 1 )
{ {
// Process the next image // Process the next image
bool result = false;
sigprocmask( SIG_BLOCK, &block_set, 0 ); sigprocmask( SIG_BLOCK, &block_set, 0 );
for ( int i = 0; i < n_monitors; i++ ) 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 ); sigprocmask( SIG_UNBLOCK, &block_set, 0 );
if ( reload ) if ( reload )

View File

@ -4,9 +4,16 @@ bool reload = false;
void hup_handler( int signal ) void hup_handler( int signal )
{ {
Info(( "Got HUP signal, reloading" ));
reload = true; reload = true;
} }
void term_handler( int signal )
{
Info(( "Got TERM signal, exiting" ));
exit( 0 );
}
void main( int argc, const char *argv[] ) void main( int argc, const char *argv[] )
{ {
int device = argv[1]?atoi( argv[1] ):0; 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_mask = block_set;
action.sa_flags = 0; action.sa_flags = 0;
sigaction( SIGHUP, &action, &old_action ); 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, SIGHUP );
sigaddset( &block_set, SIGTERM );
if ( n_monitors == 1 ) if ( n_monitors == 1 )
{ {
monitors[0]->PreCapture(); monitors[0]->PreCapture();
@ -63,8 +75,10 @@ void main( int argc, const char *argv[] )
{ {
for ( int i = 0; i < n_monitors; i++ ) for ( int i = 0; i < n_monitors; i++ )
{ {
monitors[i]->CheckFunction(); delete monitors[i];
} }
monitors = 0;
n_monitors = Monitor::Load( device, monitors );
reload = false; reload = false;
} }
} }