From f382047643ce80d95c26cabc45b9e1eee8d2ee42 Mon Sep 17 00:00:00 2001 From: stan Date: Mon, 23 Sep 2002 21:49:37 +0000 Subject: [PATCH] Simplified debug. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@51 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zmdbg.c | 225 +--------------------------------------------------- src/zmdbg.h | 4 - 2 files changed, 4 insertions(+), 225 deletions(-) diff --git a/src/zmdbg.c b/src/zmdbg.c index 67440d3e0..3c711bda0 100644 --- a/src/zmdbg.c +++ b/src/zmdbg.c @@ -13,13 +13,6 @@ #define PRESERVE_ATTEMPTS 3 -static unsigned int DbgArchive_ext = 1; -static unsigned int DbgArchive_time = 0; -static unsigned int DbgArchive_size = 0; - -static unsigned long DbgArchive_sec = 0; -static unsigned long DbgArchive_cnt = 0; - static char string[4096]; static char dbg_string[4096+512]; static const char *dbg_file; @@ -39,11 +32,7 @@ int dbg_runtime = FALSE; int dbg_add_log_id = FALSE; struct timeval dbg_start; -/* support for automatic reopening of debug files on failure to open */ static int dbg_running = FALSE; -static int dbg_reopen_cnt = 10; -static time_t dbg_log_closed = 0; -static int dbg_trig_arc = FALSE; void UsrHandler( int sig ) { @@ -54,12 +43,6 @@ void UsrHandler( int sig ) { dbg_level++; } -#if 0 - if ( SIGNAL( SIGUSR1,UsrHandler ) < 0 ) - { - Error(( "%s(), error = %s", dbg_policy_nm[dbg_sig_policy], strerror(errno) )); - } -#endif } else if ( sig == SIGUSR2 ) { @@ -67,12 +50,6 @@ void UsrHandler( int sig ) { dbg_level--; } -#if 0 - if ( SIGNAL( SIGUSR2,UsrHandler ) < 0 ) - { - Error(( "%s(), error = %s", dbg_policy_nm[dbg_sig_policy], strerror(errno) )); - } -#endif } Info(( "Debug Level Changed to %d", dbg_level )); } @@ -85,7 +62,7 @@ int GetDebugEnv( const char * const command ) /* dbg_level = 0; */ /* dbg_log[0] = '\0'; */ - env_ptr = getenv( "DB_PRINT" ); + env_ptr = getenv( "DBG_PRINT" ); if ( env_ptr == (char *)NULL ) { dbg_print = FALSE; @@ -95,7 +72,7 @@ int GetDebugEnv( const char * const command ) dbg_print = atoi( env_ptr ); } - env_ptr = getenv( "DB_FLUSH" ); + env_ptr = getenv( "DBG_FLUSH" ); if ( env_ptr == (char *)NULL ) { dbg_flush = FALSE; @@ -105,7 +82,7 @@ int GetDebugEnv( const char * const command ) dbg_flush = atoi( env_ptr ); } - env_ptr = getenv( "DB_RUNTIME" ); + env_ptr = getenv( "DBG_RUNTIME" ); if ( env_ptr == (char *)NULL ) { dbg_runtime = FALSE; @@ -143,47 +120,10 @@ int GetDebugEnv( const char * const command ) sprintf( dbg_log, "%s.%05d", env_ptr, getpid() ); } } - env_ptr = getenv( "DB_REOPEN_TRY" ); - if ( env_ptr != (char *) NULL ) - { - /* This counts the number of times the DbgOutput function - * has been called when the debug logs have been closed - * before a reopen is attempted - */ - dbg_reopen_cnt = atoi(env_ptr); - if (dbg_reopen_cnt < 1) - { - dbg_reopen_cnt = 1; - } - } return(0); } - -char *move_debug_file ( void ) -{ - int i; - static char new_dbg_log[200]; - - for ( i=0; i DbgArchive_time ) ) || - ( DbgArchive_size && ( DbgArchive_cnt > DbgArchive_size ) ) ) - { - int rtn; - - if ( ( rtn = DbgArchiveNowLocal ( tp.tv_sec ) ) != DBG_OK ) - { - return ( rtn ); - } - Info(("Reopening of debug triggered by debug library (MaxOpenTime=%d,MaxSize=%d", DbgArchive_time, DbgArchive_size)); - - } -#endif - if ( dbg_runtime ) { DbgSubtractTime( &tp, &dbg_start ); @@ -471,60 +307,13 @@ int DbgOutput( const char *fstring, ... ) } if ( dbg_log_fd != (FILE *)NULL ) { - int cnt; - - /* - * Attempt to seek to the end of the file. - * This will add about 2 micro seconds to every - * debug call. This is not considerd significant. - * Note that if it fails it fails and we don't care - * it's only to be nice to fstidy. - */ - lseek(fileno(dbg_log_fd), 0, 2); - - if ( ( cnt = fprintf ( dbg_log_fd, "%s", dbg_string ) ) > 0 ) - { - DbgArchive_cnt += cnt; - } + fprintf( dbg_log_fd, "%s", dbg_string ); if ( dbg_flush ) { fflush(dbg_log_fd); } } - else if (dbg_log_fd == NULL && dbg_running == TRUE) - { - /* in this section, debug is on because dbg_running (i.e. - * InitialiseDebug has been called and TerminateDebug has not), - * dbg_log_fd is NULL, probably from a failed close, so - * what we do is increment the count of times into DbgOutput - * function. Once this is greater than the dbg_reopen_cnt - * we try to archive (this should hopefully tidy things up a - * little, but even if it doesn't it should try reopening - * the debug log. Once it is reopened we spit out an - * extra message for information indicating the time the - * debug log got lost. Note that if we can't archive (say - * filesystem is still full) we just return as we would have - * done earlier. Also note that in the case where we've - * entered this function greater than dbg_reopen_cnt we - * reset the counter. - */ -#if 0 - count++; - if (count > dbg_reopen_cnt) - { - int rtn; - - count = 0; - if ( ( rtn = DbgArchiveNowLocal ( tp.tv_sec ) ) != DBG_OK ) - { - return ( rtn ); - } - Info(("Warning debug log closed since UTC=%d", dbg_log_closed)); - dbg_log_closed = 0; - } -#endif - } /* For Info, Warning, Errors etc we want to log them */ if ( dbg_code <= DBG_INF ) { @@ -560,9 +349,3 @@ int DbgOutput( const char *fstring, ... ) } return( strlen( string ) ); } - -void DbgArchive ( const unsigned int ArchiveTime, const unsigned int ArchiveSize ) -{ - DbgArchive_time = ArchiveTime; - DbgArchive_size = ArchiveSize; -} diff --git a/src/zmdbg.h b/src/zmdbg.h index 7800bb10a..3f656b095 100644 --- a/src/zmdbg.h +++ b/src/zmdbg.h @@ -79,15 +79,11 @@ extern "C" { int DbgInit(void); int DbgTerm(void); int DbgPrepare(const char * const file,const int line, const int code); -int DbgArchiveNow ( void ); -void DbgArchive ( const unsigned int ArchiveTime, const unsigned int ArchiveSize ); int DbgOutput(const char *fstring, ... ) __attribute__ ((format(printf, 1, 2))); #else int DbgInit(); int DbgTerm(); int DbgPrepare(); -DbgArchiveNow(); -DbgArchive(); int DbgOutput(); #endif