aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryaworsky <yaworsky>2005-12-08 08:34:48 +0000
committeryaworsky <yaworsky>2005-12-08 08:34:48 +0000
commit0782e3bcb11b1096956001aa2c3e7e07162e3a3d (patch)
treea0129dc8b2e572145484e9dd76ef104aad70770c
parentacec0f1564d24d61f4a671703748963b0f7d5754 (diff)
downloadsyslog-win32-0782e3bcb11b1096956001aa2c3e7e07162e3a3d.tar.gz
syslog-win32-0782e3bcb11b1096956001aa2c3e7e07162e3a3d.tar.xz
syslog-win32-0782e3bcb11b1096956001aa2c3e7e07162e3a3d.zip
Added --trace option.HEADmaster
Diffstat (limited to '')
-rw-r--r--daemon/main.c75
-rw-r--r--daemon/syslogd.h6
-rw-r--r--doc/src/syslogd.xml14
3 files changed, 71 insertions, 24 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 007ec54..282b697 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -48,11 +48,14 @@ static SERVICE_STATUS sstatus;
char *conf_file_name = NULL;
static char *instance_name = NULL;
static char *priority = NULL;
+static char *trace_file_name = NULL;
+
+static FILE *trace_fd;
/******************************************************************************
* display message
*/
-void display_message( FILE* fd, char* file, int line, const char* func, char* fmt, ... )
+void display_message( char* file, int line, const char* func, char* fmt, ... )
{
va_list args;
char formatstr[512];
@@ -60,9 +63,9 @@ void display_message( FILE* fd, char* file, int line, const char* func, char* fm
snprintf( formatstr, sizeof(formatstr), "%08lX:%s:%d:%s: %s",
GetCurrentThreadId(), file, line, func, fmt );
va_start( args, fmt );
- vfprintf( fd, formatstr, args );
+ vfprintf( trace_fd, formatstr, args );
va_end( args );
- fflush( fd );
+ fflush( trace_fd );
}
/******************************************************************************
@@ -389,6 +392,7 @@ static BOOL install_service()
{
BOOL ret;
char command_line[ MAX_PATH ];
+ int i;
TRACE_ENTER( "\n" );
if( __argv[0][1] == ':' )
@@ -416,6 +420,13 @@ static BOOL install_service()
strcat( command_line, " --instance " );
strcat( command_line, instance_name );
}
+ if( trace_file_name )
+ {
+ strcat( command_line, " --trace " );
+ strcat( command_line, trace_file_name );
+ }
+ for( i = 0; i < verbosity_level; i++ )
+ strcat( command_line, " -v" );
if( VER_PLATFORM_WIN32_NT == vi.dwPlatformId )
ret = winnt_InstallService( command_line );
@@ -487,7 +498,7 @@ LONG WINAPI exception_handler( PEXCEPTION_POINTERS ei )
DWORD i;
BYTE *addr;
- fprintf( stderr,
+ fprintf( trace_fd,
"*********************************\n"
"thread id:\t\t%lX\n"
"ExceptionCode:\t\t%lX\n"
@@ -504,11 +515,11 @@ LONG WINAPI exception_handler( PEXCEPTION_POINTERS ei )
ei->ExceptionRecord->NumberParameters );
for( i = 0; i < ei->ExceptionRecord->NumberParameters; i++ )
- fprintf( stderr, "\t%lX\n", ei->ExceptionRecord->ExceptionInformation[i] );
+ fprintf( trace_fd, "\t%lX\n", ei->ExceptionRecord->ExceptionInformation[i] );
#if defined(_X86_)
- fprintf( stderr,
+ fprintf( trace_fd,
"ContextFlags=%lX\n"
"CS=%lX DS=%lX ES=%lX SS=%lX FS=%lX GS=%lX\n"
"EAX=%lX EBX=%lX ECX=%lX EDX=%lX ESI=%lX EDI=%lX\n"
@@ -535,7 +546,7 @@ LONG WINAPI exception_handler( PEXCEPTION_POINTERS ei )
addr = (LPBYTE) (ei->ContextRecord->Esp);
#else
- fprintf( stderr, "FIXME: add more machines\n" );
+ fprintf( trace_fd, "FIXME: add more machines\n" );
#endif
while( !IsBadReadPtr( addr, 16 ) )
@@ -543,30 +554,30 @@ LONG WINAPI exception_handler( PEXCEPTION_POINTERS ei )
int skip = ((DWORD) addr) & 15;
BYTE *keep_addr = addr;
- fprintf( stderr, "%08lX", ((DWORD) addr) & ~15 );
+ fprintf( trace_fd, "%08lX", ((DWORD) addr) & ~15 );
for( i = 0; i < skip; i++ )
- fprintf( stderr, " " );
+ fprintf( trace_fd, " " );
for( ; i < 8; i++ )
- fprintf( stderr, " %02X", *addr++ );
+ fprintf( trace_fd, " %02X", *addr++ );
if( i == 8 )
- fputc( '-', stderr );
+ fputc( '-', trace_fd );
for( ; i < 16; i++ )
- fprintf( stderr, "%02X ", *addr++ );
- fputc( ' ', stderr );
+ fprintf( trace_fd, "%02X ", *addr++ );
+ fputc( ' ', trace_fd );
addr = keep_addr;
for( i = 0; i < skip; i++ )
- fputc( ' ', stderr );
+ fputc( ' ', trace_fd );
for( ; i < 16; i++ )
{
BYTE b = *addr++;
if( b < 32 ) b = ' ';
- fputc( b, stderr );
+ fputc( b, trace_fd );
}
- fputc( '\n', stderr );
+ fputc( '\n', trace_fd );
}
- fprintf( stderr, "*********************************\n" );
- fflush( stderr );
+ fprintf( trace_fd, "*********************************\n" );
+ fflush( trace_fd );
ExitProcess(2);
}
@@ -635,12 +646,13 @@ int main( int argc, char* argv[] )
{ "restart", no_argument, &restart_flag, 1 },
{ "instance", required_argument, NULL, 'I'},
{ "priority", required_argument, NULL, 'p'},
+ { "trace", required_argument, NULL, 't'},
{ 0, 0, 0, 0 }
};
int option_char;
int option_index;
- option_char = getopt_long( argc, argv, "c:vhirsI:p:",
+ option_char = getopt_long( argc, argv, "c:vhirsI:p:t:",
long_options, &option_index );
if( -1 == option_char )
break;
@@ -700,6 +712,10 @@ int main( int argc, char* argv[] )
SetPriorityClass( GetCurrentProcess(), pclass );
break;
}
+ case 't':
+ trace_file_name = optarg;
+ break;
+
case '?':
/* getopt_long already printed an error message. */
getopt_failure++;
@@ -712,10 +728,26 @@ int main( int argc, char* argv[] )
if( getopt_failure )
return 1;
+ /* handle flags in order of priority */
+ /* at first, open trace file, if given */
+ if( trace_file_name )
+ {
+ if( *trace_file_name == '+' )
+ trace_fd = fopen( trace_file_name + 1, "a" );
+ else
+ trace_fd = fopen( trace_file_name, "w" );
+ if( !trace_fd )
+ {
+ perror( trace_file_name );
+ trace_fd = stderr;
+ }
+ }
+ else
+ trace_fd = stderr;
+
TRACE( "local host name=%s\n", local_hostname->gstr->str );
- /* handle flags in order of priority */
- /* at first, check instance name */
+ /* check instance name */
if( instance_name )
{
service_name = g_strconcat( service_name, "_", instance_name, NULL );
@@ -772,6 +804,7 @@ int main( int argc, char* argv[] )
printf( "-I, --instance\tset instance name in the case of multiple daemons\n" );
printf( "-p, --priority\tset priority class; value may be 'normal' (default),\n"
"\t\t'high', or 'highest'\n" );
+ printf( "-t, --trace\toutput trace and error messages to the specified file\n" );
printf( "-h, --help\tdisplay this message\n" );
printf( "--version\tdisplay version information\n" );
return 0;
diff --git a/daemon/syslogd.h b/daemon/syslogd.h
index 05d2b9a..35cd140 100644
--- a/daemon/syslogd.h
+++ b/daemon/syslogd.h
@@ -16,13 +16,13 @@
*/
extern int verbosity_level;
-extern void display_message( FILE* fd, char* file, int line, const char* func, char* fmt, ... );
+extern void display_message( char* file, int line, const char* func, char* fmt, ... );
#ifdef HAVE_DEBUG
# define DO_TRACE( verbosity, fmt... ) \
do { \
if( verbosity <= verbosity_level ) \
- display_message( stderr, __FILE__, __LINE__, __FUNCTION__, fmt ); \
+ display_message( __FILE__, __LINE__, __FUNCTION__, fmt ); \
} while(0)
# define TRACE_2( fmt... ) DO_TRACE( 2, fmt )
# define TRACE( fmt... ) DO_TRACE( 1, fmt )
@@ -32,7 +32,7 @@ extern void display_message( FILE* fd, char* file, int line, const char* func, c
#endif
#define TRACE_ENTER TRACE_2
#define TRACE_LEAVE TRACE_2
-#define ERR( fmt... ) display_message( stderr, __FILE__, __LINE__, __FUNCTION__, fmt )
+#define ERR( fmt... ) display_message( __FILE__, __LINE__, __FUNCTION__, fmt )
/* refcounted string */
struct string
diff --git a/doc/src/syslogd.xml b/doc/src/syslogd.xml
index 66b7b4e..f6f29d2 100644
--- a/doc/src/syslogd.xml
+++ b/doc/src/syslogd.xml
@@ -26,6 +26,7 @@
<arg choice="opt">--restart</arg>
<group choice="opt"><arg>-s</arg><arg>--shutdown</arg></group>
<arg choice="opt">--start</arg>
+<group choice="opt"><arg>-t</arg><arg>--trace</arg><replaceable>&nbsp;file</replaceable></group>
<group choice="opt"><arg>-v</arg><arg>--verbose</arg></group>
<arg choice="opt">--version</arg>
</cmdsynopsis>
@@ -130,6 +131,19 @@ Start installed service.
</varlistentry>
<varlistentry>
<term>
+<option>-t</option> | <option>--trace</option><replaceable>&nbsp;file</replaceable>
+ </term>
+ <listitem>
+ <para>
+Write error and trace messages to the specified file.
+If filename begins with <quote>+</quote>, new messages will be appended to the
+end of existing file.
+Otherwise the file will be overwritten.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
<option>-v</option> | <option>--verbose</option>
</term>
<listitem>