]> git.sur5r.net Git - openldap/commitdiff
Added LBER_OPT_LOG_PRINT_FILE to redirect the output of ber_error_print.
authorHoward Chu <hyc@openldap.org>
Thu, 11 May 2000 09:39:33 +0000 (09:39 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 11 May 2000 09:39:33 +0000 (09:39 +0000)
Used mainly on NT since stderr doesn't exist when slapd runs as a service.

include/lber.h
libraries/liblber/bprint.c
libraries/liblber/options.c
libraries/liblutil/debug.c

index 4f3cebc245529f5086873f58ccd8282940c1e372..5179c7aa4d68d38816eb2e4b2fc49c17a928e503 100644 (file)
@@ -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 ));
 
index 5c615a129175015084aaf5d9ba5500b5a134f1af..f2e2a08a41288b7fffeb874f62d60c52dddece30 100644 (file)
 
 #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;
index 03a4e3c56aae2cab66720efdf02d640092dd356f..62f4fcf4175924b61167020b732c12673d5bbab8 100644 (file)
@@ -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;
index a6fc5064d2d9d7861461bc5753b60e9658e56b02..2ebce49700b6a3b73b292bab4a2d00a212c0f488 100644 (file)
 
 #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