Revamped debug initialisation and config loading.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1208 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
parent
5ed307f0c5
commit
dc3b3691a0
|
@ -60,6 +60,7 @@ void zmLoadConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose( cfg);
|
fclose( cfg);
|
||||||
|
zmDbConnect();
|
||||||
config.Load();
|
config.Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,13 @@ static const char *zm_dbg_file;
|
||||||
static int zm_dbg_line;
|
static int zm_dbg_line;
|
||||||
static int zm_dbg_code;
|
static int zm_dbg_code;
|
||||||
static char zm_dbg_class[4];
|
static char zm_dbg_class[4];
|
||||||
const char *zm_dbg_name = "";
|
|
||||||
int zm_dbg_pid = -1;
|
|
||||||
static int zm_dbg_switched_on = FALSE;
|
|
||||||
|
|
||||||
|
char zm_dbg_name[64];
|
||||||
|
char zm_dbg_id[64];
|
||||||
int zm_dbg_level = 0;
|
int zm_dbg_level = 0;
|
||||||
char zm_dbg_log[128] = "";
|
int zm_dbg_pid = -1;
|
||||||
|
|
||||||
|
char zm_dbg_log[PATH_MAX] = "";
|
||||||
FILE *zm_dbg_log_fd = (FILE *)NULL;
|
FILE *zm_dbg_log_fd = (FILE *)NULL;
|
||||||
int zm_dbg_print = FALSE;
|
int zm_dbg_print = FALSE;
|
||||||
int zm_dbg_flush = FALSE;
|
int zm_dbg_flush = FALSE;
|
||||||
|
@ -55,7 +56,6 @@ void zmUsrHandler( int sig )
|
||||||
{
|
{
|
||||||
if( sig == SIGUSR1)
|
if( sig == SIGUSR1)
|
||||||
{
|
{
|
||||||
zm_dbg_switched_on = TRUE;
|
|
||||||
if ( zm_dbg_level < 9 )
|
if ( zm_dbg_level < 9 )
|
||||||
{
|
{
|
||||||
zm_dbg_level++;
|
zm_dbg_level++;
|
||||||
|
@ -71,7 +71,7 @@ void zmUsrHandler( int sig )
|
||||||
Info(( "Debug Level Changed to %d", zm_dbg_level ));
|
Info(( "Debug Level Changed to %d", zm_dbg_level ));
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmGetDebugEnv( const char * const command )
|
int zmGetDebugEnv()
|
||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
char *env_ptr;
|
char *env_ptr;
|
||||||
|
@ -109,14 +109,37 @@ int zmGetDebugEnv( const char * const command )
|
||||||
zm_dbg_runtime = atoi( env_ptr );
|
zm_dbg_runtime = atoi( env_ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer,"ZM_DBG_LEVEL_%s",command);
|
env_ptr = NULL;
|
||||||
|
sprintf(buffer,"ZM_DBG_LEVEL_%s_%s",zm_dbg_name,zm_dbg_id);
|
||||||
env_ptr = getenv(buffer);
|
env_ptr = getenv(buffer);
|
||||||
if( env_ptr != (char *)NULL )
|
if ( env_ptr == (char *)NULL )
|
||||||
|
{
|
||||||
|
sprintf(buffer,"ZM_DBG_LEVEL_%s",zm_dbg_name);
|
||||||
|
env_ptr = getenv(buffer);
|
||||||
|
if ( env_ptr == (char *)NULL )
|
||||||
|
{
|
||||||
|
sprintf(buffer,"ZM_DBG_LEVEL");
|
||||||
|
env_ptr = getenv(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( env_ptr != (char *)NULL )
|
||||||
{
|
{
|
||||||
zm_dbg_level = atoi(env_ptr);
|
zm_dbg_level = atoi(env_ptr);
|
||||||
}
|
}
|
||||||
snprintf( buffer, sizeof(buffer), "ZM_DBG_LOG_%s", command );
|
|
||||||
env_ptr = getenv( buffer );
|
env_ptr = NULL;
|
||||||
|
sprintf(buffer,"ZM_DBG_LOG_%s_%s",zm_dbg_name,zm_dbg_id);
|
||||||
|
env_ptr = getenv(buffer);
|
||||||
|
if ( env_ptr == (char *)NULL )
|
||||||
|
{
|
||||||
|
sprintf(buffer,"ZM_DBG_LOG_%s",zm_dbg_name);
|
||||||
|
env_ptr = getenv(buffer);
|
||||||
|
if ( env_ptr == (char *)NULL )
|
||||||
|
{
|
||||||
|
sprintf(buffer,"ZM_DBG_LOG");
|
||||||
|
env_ptr = getenv(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( env_ptr != (char *)NULL )
|
if ( env_ptr != (char *)NULL )
|
||||||
{
|
{
|
||||||
/* If we do not want to add a pid to the debug logs
|
/* If we do not want to add a pid to the debug logs
|
||||||
|
@ -138,10 +161,10 @@ int zmGetDebugEnv( const char * const command )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmDebugInitialise()
|
int zmDebugInitialise( const char *name, const char *id, int level )
|
||||||
{
|
{
|
||||||
FILE *tmp_fp;
|
FILE *tmp_fp;
|
||||||
|
|
||||||
|
@ -153,6 +176,10 @@ int zmDebugInitialise()
|
||||||
|
|
||||||
Debug(1,("Initialising Debug"));
|
Debug(1,("Initialising Debug"));
|
||||||
|
|
||||||
|
strncpy( zm_dbg_name, name, sizeof(zm_dbg_name) );
|
||||||
|
strncpy( zm_dbg_id, id, sizeof(zm_dbg_id) );
|
||||||
|
zm_dbg_level = level;
|
||||||
|
|
||||||
/* Now set up the syslog stuff */
|
/* Now set up the syslog stuff */
|
||||||
(void) openlog( zm_dbg_name, LOG_PID|LOG_NDELAY, LOG_LOCAL1 );
|
(void) openlog( zm_dbg_name, LOG_PID|LOG_NDELAY, LOG_LOCAL1 );
|
||||||
|
|
||||||
|
@ -161,7 +188,7 @@ int zmDebugInitialise()
|
||||||
|
|
||||||
zm_dbg_pid = getpid();
|
zm_dbg_pid = getpid();
|
||||||
zm_dbg_log_fd = (FILE *)NULL;
|
zm_dbg_log_fd = (FILE *)NULL;
|
||||||
if( (status = zmGetDebugEnv(zm_dbg_name) ) < 0)
|
if( (status = zmGetDebugEnv() ) < 0)
|
||||||
{
|
{
|
||||||
Error(("Debug Environment Error, status = %d",status));
|
Error(("Debug Environment Error, status = %d",status));
|
||||||
return(ZM_DBG_ERROR);
|
return(ZM_DBG_ERROR);
|
||||||
|
@ -208,9 +235,9 @@ int zmDebugInitialise()
|
||||||
return(ZM_DBG_OK);
|
return(ZM_DBG_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmDbgInit()
|
int zmDbgInit( const char *name, const char *id, int level )
|
||||||
{
|
{
|
||||||
return((zmDebugInitialise() == ZM_DBG_OK ? 0 : 1));
|
return((zmDebugInitialise( name, id, level ) == ZM_DBG_OK ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmDebugTerminate()
|
int zmDebugTerminate()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
|
@ -96,14 +97,14 @@ extern "C" {
|
||||||
|
|
||||||
/* function declarations */
|
/* function declarations */
|
||||||
void zmUsrHandler( int sig );
|
void zmUsrHandler( int sig );
|
||||||
int zmGetDebugEnv( const char * const command );
|
int zmGetDebugEnv( void );
|
||||||
int zmDebugInitialise( void );
|
int zmDebugInitialise( const char *name, const char *id, int level );
|
||||||
int zmDebugTerminate( void );
|
int zmDebugTerminate( void );
|
||||||
void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 );
|
void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 );
|
||||||
|
|
||||||
|
|
||||||
#if defined(__STDC__) || defined(__cplusplus)
|
#if defined(__STDC__) || defined(__cplusplus)
|
||||||
int zmDbgInit(void);
|
int zmDbgInit( const char *name, const char *id, int level );
|
||||||
int zmDbgTerm(void);
|
int zmDbgTerm(void);
|
||||||
int zmDbgPrepare(const char * const file,const int line, const int code);
|
int zmDbgPrepare(const char * const file,const int line, const int code);
|
||||||
int zmDbgOutput(const char *fstring, ... ) __attribute__ ((format(printf, 1, 2)));
|
int zmDbgOutput(const char *fstring, ... ) __attribute__ ((format(printf, 1, 2)));
|
||||||
|
@ -121,7 +122,8 @@ extern char zm_dbg_log[];
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
extern FILE *zm_dbg_log_fd;
|
extern FILE *zm_dbg_log_fd;
|
||||||
extern const char *zm_dbg_name;
|
extern char zm_dbg_name[];
|
||||||
|
extern char zm_dbg_id[];
|
||||||
extern int zm_dbg_print;
|
extern int zm_dbg_print;
|
||||||
extern int zm_dbg_flush;
|
extern int zm_dbg_flush;
|
||||||
extern int zm_dbg_add_log_id;
|
extern int zm_dbg_add_log_id;
|
||||||
|
@ -145,7 +147,7 @@ extern int zm_dbg_add_log_id;
|
||||||
#define Enter()
|
#define Enter()
|
||||||
#define Exit()
|
#define Exit()
|
||||||
|
|
||||||
#define zmDbgInit()
|
#define zmDbgInit(name,id,level)
|
||||||
#define zmDbgTerm()
|
#define zmDbgTerm()
|
||||||
|
|
||||||
#endif /* !ZM_DBG_OFF */
|
#endif /* !ZM_DBG_OFF */
|
||||||
|
|
11
src/zma.cpp
11
src/zma.cpp
|
@ -118,18 +118,13 @@ int main( int argc, char *argv[] )
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbg_name_string[16];
|
char dbg_id_string[16];
|
||||||
snprintf( dbg_name_string, sizeof(dbg_name_string), "zma-m%d", id );
|
snprintf( dbg_id_string, sizeof(dbg_id_string), "m%d", id );
|
||||||
zm_dbg_name = dbg_name_string;
|
|
||||||
//snprintf( zm_dbg_log, sizeof(zm_dbg_log), "/tmp/zma-%d.log", id );
|
|
||||||
//zm_dbg_level = 1;
|
|
||||||
|
|
||||||
zmDbgInit();
|
zmDbgInit( "zma", dbg_id_string, 0 );
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
Monitor *monitor = Monitor::Load( id, true, Monitor::ANALYSIS );
|
Monitor *monitor = Monitor::Load( id, true, Monitor::ANALYSIS );
|
||||||
|
|
||||||
if ( monitor )
|
if ( monitor )
|
||||||
|
|
15
src/zmc.cpp
15
src/zmc.cpp
|
@ -125,29 +125,24 @@ int main( int argc, char *argv[] )
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
zm_dbg_name = "zmc";
|
char dbg_id_string[16];
|
||||||
|
|
||||||
char dbg_name_string[16];
|
|
||||||
if ( device >= 0 )
|
if ( device >= 0 )
|
||||||
{
|
{
|
||||||
snprintf( dbg_name_string, sizeof(dbg_name_string), "zmc-d%d", device );
|
snprintf( dbg_id_string, sizeof(dbg_id_string), "d%d", device );
|
||||||
}
|
}
|
||||||
else if ( host[0] )
|
else if ( host[0] )
|
||||||
{
|
{
|
||||||
snprintf( dbg_name_string, sizeof(dbg_name_string), "zmc-h%s", host );
|
snprintf( dbg_id_string, sizeof(dbg_id_string), "h%s", host );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf( dbg_name_string, sizeof(dbg_name_string), "zmc-m%d", monitor_id );
|
snprintf( dbg_id_string, sizeof(dbg_id_string), "m%d", monitor_id );
|
||||||
}
|
}
|
||||||
zm_dbg_name = dbg_name_string;
|
|
||||||
|
|
||||||
zmDbgInit();
|
zmDbgInit( "zmc", dbg_id_string, 0 );
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
Monitor **monitors = 0;
|
Monitor **monitors = 0;
|
||||||
int n_monitors = 0;
|
int n_monitors = 0;
|
||||||
if ( device >= 0 )
|
if ( device >= 0 )
|
||||||
|
|
11
src/zmf.cpp
11
src/zmf.cpp
|
@ -185,18 +185,13 @@ int main( int argc, char *argv[] )
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbg_name_string[16];
|
char dbg_id_string[16];
|
||||||
snprintf( dbg_name_string, sizeof(dbg_name_string), "zmf-m%d", id );
|
snprintf( dbg_id_string, sizeof(dbg_id_string), "m%d", id );
|
||||||
zm_dbg_name = dbg_name_string;
|
|
||||||
//snprintf( zm_dbg_log, sizeof(zm_dbg_log), "/tmp/zmf-%d.log", id );
|
|
||||||
//zm_dbg_level = 1;
|
|
||||||
|
|
||||||
zmDbgInit();
|
zmDbgInit( "zmf", dbg_id_string, 0 );
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
Monitor *monitor = Monitor::Load( id, false );
|
Monitor *monitor = Monitor::Load( id, false );
|
||||||
|
|
||||||
if ( !monitor )
|
if ( !monitor )
|
||||||
|
|
|
@ -89,10 +89,7 @@ bool fixVideoDevice( int device )
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
char dbg_name_string[16] = "zmfix";
|
zmDbgInit( "zmfix", "", -1 );
|
||||||
zm_dbg_name = dbg_name_string;
|
|
||||||
|
|
||||||
zmDbgInit();
|
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
|
@ -110,8 +107,6 @@ int main( int argc, char *argv[] )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Only do registered devices
|
// Only do registered devices
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
static char sql[BUFSIZ];
|
static char sql[BUFSIZ];
|
||||||
//snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Function != 'None' and Type = 'Local'" );
|
//snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Function != 'None' and Type = 'Local'" );
|
||||||
snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Type = 'Local'" );
|
snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Type = 'Local'" );
|
||||||
|
|
16
src/zms.cpp
16
src/zms.cpp
|
@ -135,32 +135,18 @@ int main( int argc, const char *argv[] )
|
||||||
char auth[64] = "";
|
char auth[64] = "";
|
||||||
char user[64] = "";
|
char user[64] = "";
|
||||||
|
|
||||||
zm_dbg_name = "zms";
|
|
||||||
|
|
||||||
bool nph = false;
|
bool nph = false;
|
||||||
const char *basename = strrchr( argv[0], '/' );
|
const char *basename = strrchr( argv[0], '/' );
|
||||||
const char *nph_prefix = "nph-";
|
const char *nph_prefix = "nph-";
|
||||||
if ( basename && !strncmp( basename+1, nph_prefix, strlen(nph_prefix) ) )
|
if ( basename && !strncmp( basename+1, nph_prefix, strlen(nph_prefix) ) )
|
||||||
{
|
{
|
||||||
zm_dbg_name = "nph-zms";
|
|
||||||
nph = true;
|
nph = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//extern char **environ;
|
zmDbgInit( "zms", "", 0 );
|
||||||
//char **env_ptr = environ;
|
|
||||||
//while ( *env_ptr )
|
|
||||||
//{
|
|
||||||
//printf( "X-Env: %s\n", *env_ptr );
|
|
||||||
//env_ptr++;
|
|
||||||
//}
|
|
||||||
//exit( 0 );
|
|
||||||
|
|
||||||
zmDbgInit();
|
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
|
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
const char *query = getenv( "QUERY_STRING" );
|
const char *query = getenv( "QUERY_STRING" );
|
||||||
if ( query )
|
if ( query )
|
||||||
{
|
{
|
||||||
|
|
|
@ -347,13 +347,9 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
//printf( "Monitor %d, Function %d\n", mon_id, function );
|
//printf( "Monitor %d, Function %d\n", mon_id, function );
|
||||||
|
|
||||||
zm_dbg_name = "zmu";
|
zmDbgInit( "zmu", "", -1 );
|
||||||
zm_dbg_level = -1;
|
|
||||||
|
|
||||||
zmDbgInit();
|
|
||||||
|
|
||||||
zmLoadConfig();
|
zmLoadConfig();
|
||||||
zmDbConnect();
|
|
||||||
|
|
||||||
ValidateAccess( username, password, mon_id, function );
|
ValidateAccess( username, password, mon_id, function );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue