From: Howard Chu Date: Thu, 11 May 2000 09:39:33 +0000 (+0000) Subject: Added LBER_OPT_LOG_PRINT_FILE to redirect the output of ber_error_print. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~3013 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=65d7521be1b5b0a2218cca8e8896f7fc459bd418;p=openldap Added LBER_OPT_LOG_PRINT_FILE to redirect the output of ber_error_print. Used mainly on NT since stderr doesn't exist when slapd runs as a service. --- diff --git a/include/lber.h b/include/lber.h index 4f3cebc245..5179c7aa4d 100644 --- a/include/lber.h +++ b/include/lber.h @@ -105,6 +105,7 @@ typedef int (*BERTranslateProc) LDAP_P(( #define LBER_OPT_LOG_PRINT_FN 0x8001 #define LBER_OPT_MEMORY_FNS 0x8002 #define LBER_OPT_ERROR_FN 0x8003 +#define LBER_OPT_LOG_PRINT_FILE 0x8004 typedef int* (*BER_ERRNO_FN) LDAP_P(( void )); diff --git a/libraries/liblber/bprint.c b/libraries/liblber/bprint.c index 5c615a1291..f2e2a08a41 100644 --- a/libraries/liblber/bprint.c +++ b/libraries/liblber/bprint.c @@ -14,6 +14,15 @@ #include "lber-int.h" +/* + * We don't just set ber_pvt_err_file to stderr here, because in NT, + * stderr is a symbol imported from a DLL. As such, the compiler + * doesn't recognize the symbol as having a constant address. Thus + * we set ber_pvt_err_file to stderr later, when it first gets + * referenced. + */ +FILE *ber_pvt_err_file; + /* * ber errno */ @@ -38,8 +47,19 @@ ber_error_print( char *data ) { assert( data != NULL ); + if (!ber_pvt_err_file) + ber_pvt_err_file = stderr; + + fputs( data, ber_pvt_err_file ); + + /* Print to both streams */ + if (ber_pvt_err_file != stderr) + { fputs( data, stderr ); fflush( stderr ); + } + + fflush( ber_pvt_err_file ); } BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print; diff --git a/libraries/liblber/options.c b/libraries/liblber/options.c index 03a4e3c56a..62f4fcf417 100644 --- a/libraries/liblber/options.c +++ b/libraries/liblber/options.c @@ -10,6 +10,8 @@ #include "lber-int.h" +extern void * ber_pvt_err_file; /* bprint.c */ + struct lber_options ber_int_options = { LBER_UNINITIALIZED, 0, 0 }; @@ -130,6 +132,9 @@ ber_set_option( } else if(option == LBER_OPT_LOG_PRINT_FN) { ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue; return LBER_OPT_SUCCESS; + } else if(option == LBER_OPT_LOG_PRINT_FILE) { + ber_pvt_err_file = (void *) invalue; + return LBER_OPT_SUCCESS; } ber_errno = LBER_ERROR_PARAM; diff --git a/libraries/liblutil/debug.c b/libraries/liblutil/debug.c index a6fc5064d2..2ebce49700 100644 --- a/libraries/liblutil/debug.c +++ b/libraries/liblutil/debug.c @@ -29,12 +29,14 @@ #include "ldap_log.h" #include "ldap_defaults.h" +#include "lber.h" static FILE *log_file; int lutil_debug_file( FILE *file ) { log_file = file; + ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file ); return 0; } @@ -57,9 +59,10 @@ void (lutil_debug)( int level, int debug, const char *fmt, ... ) if ( log_file == NULL ) return; + + ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file ); } #endif - va_start( vl, fmt ); #ifdef HAVE_VSNPRINTF