Bug 308 - Added improved signal handling and backtracing.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1916 e3e1d417-86f3-4887-817a-d78f3d33393fpull/27/merge
parent
132d582edf
commit
a0b3e2a5a3
|
@ -35,6 +35,7 @@ zm_SOURCES = \
|
||||||
zm_mpeg.cpp \
|
zm_mpeg.cpp \
|
||||||
zm_jpeg.c \
|
zm_jpeg.c \
|
||||||
zm_regexp.cpp \
|
zm_regexp.cpp \
|
||||||
|
zm_signal.cpp \
|
||||||
zm_buffer.cpp \
|
zm_buffer.cpp \
|
||||||
zm_debug.c
|
zm_debug.c
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ noinst_HEADERS = \
|
||||||
zm_jpeg.h \
|
zm_jpeg.h \
|
||||||
zm_mpeg.h \
|
zm_mpeg.h \
|
||||||
zm_regexp.h \
|
zm_regexp.h \
|
||||||
|
zm_signal.h \
|
||||||
zm_buffer.h
|
zm_buffer.h
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
|
|
79
src/zma.cpp
79
src/zma.cpp
|
@ -22,60 +22,9 @@
|
||||||
|
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
#include "zm_db.h"
|
#include "zm_db.h"
|
||||||
|
#include "zm_signal.h"
|
||||||
#include "zm_monitor.h"
|
#include "zm_monitor.h"
|
||||||
|
|
||||||
void zm_die_handler( int signal )
|
|
||||||
{
|
|
||||||
#if HAVE_DECL_STRSIGNAL
|
|
||||||
char * error = strsignal(signal);
|
|
||||||
size_t errorStringSize = strlen(error) + strlen("Got signal (), crashing.");
|
|
||||||
char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char.
|
|
||||||
(void) snprintf(errorString, errorStringSize, "Got signal (%s), crashing.", error);
|
|
||||||
|
|
||||||
Error(( (const char *)errorString ));
|
|
||||||
free(errorString);
|
|
||||||
#else /* HAVE_DECL_STRSIGNAL */
|
|
||||||
Error(( "Got signal %d, crashing", signal ));
|
|
||||||
#endif /* HAVE_DECL_STRSIGNAL */
|
|
||||||
exit( signal );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zma_terminate = false;
|
|
||||||
|
|
||||||
void zm_term_handler( int signal )
|
|
||||||
{
|
|
||||||
#if HAVE_DECL_STRSIGNAL
|
|
||||||
char * error = strsignal(signal);
|
|
||||||
size_t errorStringSize = strlen(error) + strlen("Got signal (), exiting.");
|
|
||||||
char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char.
|
|
||||||
(void) snprintf(errorString, errorStringSize, "Got signal (%s), exiting.", error);
|
|
||||||
|
|
||||||
Info(( (const char *)errorString ));
|
|
||||||
free(errorString);
|
|
||||||
#else /* HAVE_DECL_STRSIGNAL */
|
|
||||||
Info(( "Got TERM signal, exiting" ));
|
|
||||||
#endif /* HAVE_DECL_STRSIGNAL */
|
|
||||||
zma_terminate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zma_reload = false;
|
|
||||||
|
|
||||||
void zm_hup_handler( int signal )
|
|
||||||
{
|
|
||||||
#if HAVE_DECL_STRSIGNAL
|
|
||||||
char * error = strsignal(signal);
|
|
||||||
size_t errorStringSize = strlen(error) + strlen("Got signal (), reloading.");
|
|
||||||
char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char.
|
|
||||||
(void) snprintf(errorString, errorStringSize, "Got signal (%s), reloading.", error);
|
|
||||||
|
|
||||||
Info(( (const char *)errorString ));
|
|
||||||
free(errorString);
|
|
||||||
#else /* HAVE_DECL_STRSIGNAL */
|
|
||||||
Info(( "Got HUP signal, reloading" ));
|
|
||||||
#endif /* HAVE_DECL_STRSIGNAL */
|
|
||||||
zma_reload = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Usage()
|
void Usage()
|
||||||
{
|
{
|
||||||
fprintf( stderr, "zma -m <monitor_id>\n" );
|
fprintf( stderr, "zma -m <monitor_id>\n" );
|
||||||
|
@ -154,27 +103,15 @@ int main( int argc, char *argv[] )
|
||||||
Event::OpenFrameSocket( monitor->Id() );
|
Event::OpenFrameSocket( monitor->Id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zmSetDefaultHupHandler();
|
||||||
|
zmSetDefaultTermHandler();
|
||||||
|
zmSetDefaultDieHandler();
|
||||||
|
|
||||||
sigset_t block_set;
|
sigset_t block_set;
|
||||||
sigemptyset( &block_set );
|
sigemptyset( &block_set );
|
||||||
struct sigaction action, old_action;
|
struct sigaction action, old_action;
|
||||||
|
|
||||||
action.sa_handler = zm_hup_handler;
|
while( !zm_terminate )
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGHUP, &action, &old_action );
|
|
||||||
|
|
||||||
action.sa_handler = zm_term_handler;
|
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGTERM, &action, &old_action );
|
|
||||||
|
|
||||||
action.sa_handler = zm_die_handler;
|
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGBUS, &action, &old_action );
|
|
||||||
sigaction( SIGSEGV, &action, &old_action );
|
|
||||||
|
|
||||||
while( !zma_terminate )
|
|
||||||
{
|
{
|
||||||
// Process the next image
|
// Process the next image
|
||||||
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
||||||
|
@ -182,10 +119,10 @@ int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
usleep( monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE );
|
usleep( monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE );
|
||||||
}
|
}
|
||||||
if ( zma_reload )
|
if ( zm_reload )
|
||||||
{
|
{
|
||||||
monitor->Reload();
|
monitor->Reload();
|
||||||
zma_reload = false;
|
zm_reload = false;
|
||||||
}
|
}
|
||||||
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
||||||
}
|
}
|
||||||
|
|
20
src/zmc.cpp
20
src/zmc.cpp
|
@ -23,16 +23,9 @@
|
||||||
|
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
#include "zm_db.h"
|
#include "zm_db.h"
|
||||||
|
#include "zm_signal.h"
|
||||||
#include "zm_monitor.h"
|
#include "zm_monitor.h"
|
||||||
|
|
||||||
bool zmc_terminate = false;
|
|
||||||
|
|
||||||
void zmc_term_handler( int /* signal */ )
|
|
||||||
{
|
|
||||||
Info(( "Got TERM signal, exiting" ));
|
|
||||||
zmc_terminate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Usage()
|
void Usage()
|
||||||
{
|
{
|
||||||
fprintf( stderr, "zmc -d <device_path> or -H <host> -P <port> -p <path> or -f <file_path> or -m <monitor_id>\n" );
|
fprintf( stderr, "zmc -d <device_path> or -H <host> -P <port> -p <path> or -f <file_path> or -m <monitor_id>\n" );
|
||||||
|
@ -188,15 +181,14 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
|
|
||||||
Info(( "Starting Capture" ));
|
Info(( "Starting Capture" ));
|
||||||
|
|
||||||
|
zmSetDefaultTermHandler();
|
||||||
|
zmSetDefaultDieHandler();
|
||||||
|
|
||||||
sigset_t block_set;
|
sigset_t block_set;
|
||||||
sigemptyset( &block_set );
|
sigemptyset( &block_set );
|
||||||
struct sigaction action, old_action;
|
struct sigaction action, old_action;
|
||||||
|
|
||||||
action.sa_handler = zmc_term_handler;
|
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGTERM, &action, &old_action );
|
|
||||||
|
|
||||||
sigaddset( &block_set, SIGUSR1 );
|
sigaddset( &block_set, SIGUSR1 );
|
||||||
sigaddset( &block_set, SIGUSR2 );
|
sigaddset( &block_set, SIGUSR2 );
|
||||||
if ( device[0] && n_monitors == 1 )
|
if ( device[0] && n_monitors == 1 )
|
||||||
|
@ -220,7 +212,7 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct DeltaTimeval delta_time;
|
struct DeltaTimeval delta_time;
|
||||||
while( !zmc_terminate )
|
while( !zm_terminate )
|
||||||
{
|
{
|
||||||
/* grab a new one */
|
/* grab a new one */
|
||||||
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
||||||
|
|
48
src/zmf.cpp
48
src/zmf.cpp
|
@ -33,43 +33,11 @@
|
||||||
|
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
#include "zm_db.h"
|
#include "zm_db.h"
|
||||||
//#include "zm_debug.h"
|
#include "zm_signal.h"
|
||||||
#include "zm_monitor.h"
|
#include "zm_monitor.h"
|
||||||
|
|
||||||
#include "zmf.h"
|
#include "zmf.h"
|
||||||
|
|
||||||
void zm_die_handler( int signal )
|
|
||||||
{
|
|
||||||
#if HAVE_DECL_STRSIGNAL
|
|
||||||
char * error = strsignal(signal);
|
|
||||||
size_t errorStringSize = strlen(error) + strlen("Got signal (), crashing.");
|
|
||||||
char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char.
|
|
||||||
(void) snprintf(errorString, errorStringSize, "Got signal (%s), crashing.", error);
|
|
||||||
|
|
||||||
Error(( (const char *)errorString ));
|
|
||||||
free(errorString);
|
|
||||||
#else /* HAVE_DECL_STRSIGNAL */
|
|
||||||
Error(( "Got signal %d, crashing", signal ));
|
|
||||||
#endif /* HAVE_DECL_STRSIGNAL */
|
|
||||||
exit( signal );
|
|
||||||
}
|
|
||||||
|
|
||||||
void zm_term_handler( int signal )
|
|
||||||
{
|
|
||||||
#if HAVE_DECL_STRSIGNAL
|
|
||||||
char * error = strsignal(signal);
|
|
||||||
size_t errorStringSize = strlen(error) + strlen("Got signal (), exiting.");
|
|
||||||
char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char.
|
|
||||||
(void) snprintf(errorString, errorStringSize, "Got signal (%s), exiting.", error);
|
|
||||||
|
|
||||||
Info(( (const char *)errorString ));
|
|
||||||
free(errorString);
|
|
||||||
#else /* HAVE_DECL_STRSIGNAL */
|
|
||||||
Info(( "Got TERM signal, exiting" ));
|
|
||||||
#endif /* HAVE_DECL_STRSIGNAL */
|
|
||||||
exit( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
int OpenSocket( int monitor_id )
|
int OpenSocket( int monitor_id )
|
||||||
{
|
{
|
||||||
int sd = socket( AF_UNIX, SOCK_STREAM, 0);
|
int sd = socket( AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
@ -205,21 +173,13 @@ int main( int argc, char *argv[] )
|
||||||
snprintf( capt_path, sizeof(capt_path), "%s/%d/%%d/%%0%dd-capture.jpg", config.dir_events, monitor->Id(), config.event_image_digits );
|
snprintf( capt_path, sizeof(capt_path), "%s/%d/%%d/%%0%dd-capture.jpg", config.dir_events, monitor->Id(), config.event_image_digits );
|
||||||
snprintf( anal_path, sizeof(anal_path), "%s/%d/%%d/%%0%dd-analyse.jpg", config.dir_events, monitor->Id(), config.event_image_digits );
|
snprintf( anal_path, sizeof(anal_path), "%s/%d/%%d/%%0%dd-analyse.jpg", config.dir_events, monitor->Id(), config.event_image_digits );
|
||||||
|
|
||||||
|
zmSetDefaultTermHandler();
|
||||||
|
zmSetDefaultDieHandler();
|
||||||
|
|
||||||
sigset_t block_set;
|
sigset_t block_set;
|
||||||
sigemptyset( &block_set );
|
sigemptyset( &block_set );
|
||||||
struct sigaction action, old_action;
|
struct sigaction action, old_action;
|
||||||
|
|
||||||
action.sa_handler = zm_term_handler;
|
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGTERM, &action, &old_action );
|
|
||||||
|
|
||||||
action.sa_handler = zm_die_handler;
|
|
||||||
action.sa_mask = block_set;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
sigaction( SIGBUS, &action, &old_action );
|
|
||||||
sigaction( SIGSEGV, &action, &old_action );
|
|
||||||
|
|
||||||
int sd = OpenSocket( monitor->Id() );
|
int sd = OpenSocket( monitor->Id() );
|
||||||
|
|
||||||
FrameHeader frame_header = { 0, 0, false, 0 };
|
FrameHeader frame_header = { 0, 0, false, 0 };
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
#include "zm_db.h"
|
#include "zm_db.h"
|
||||||
#include "zm_user.h"
|
#include "zm_user.h"
|
||||||
|
#include "zm_signal.h"
|
||||||
#include "zm_monitor.h"
|
#include "zm_monitor.h"
|
||||||
|
|
||||||
bool ValidateAccess( User *user, int mon_id )
|
bool ValidateAccess( User *user, int mon_id )
|
||||||
|
@ -74,6 +75,9 @@ int main( int argc, const char *argv[] )
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
|
zmSetDefaultTermHandler();
|
||||||
|
zmSetDefaultDieHandler();
|
||||||
|
|
||||||
const char *query = getenv( "QUERY_STRING" );
|
const char *query = getenv( "QUERY_STRING" );
|
||||||
if ( query )
|
if ( query )
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
#include "zm_db.h"
|
#include "zm_db.h"
|
||||||
#include "zm_user.h"
|
#include "zm_user.h"
|
||||||
|
#include "zm_signal.h"
|
||||||
#include "zm_monitor.h"
|
#include "zm_monitor.h"
|
||||||
#include "zm_local_camera.h"
|
#include "zm_local_camera.h"
|
||||||
|
|
||||||
|
@ -348,6 +349,9 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
|
zmSetDefaultTermHandler();
|
||||||
|
zmSetDefaultDieHandler();
|
||||||
|
|
||||||
User *user = 0;
|
User *user = 0;
|
||||||
|
|
||||||
if ( config.opt_use_auth )
|
if ( config.opt_use_auth )
|
||||||
|
|
Loading…
Reference in New Issue