From: Kurt Zeilenga Date: Mon, 21 Jun 1999 22:36:13 +0000 (+0000) Subject: Add missing arguments to Debug() calls... and adapt nt_debug for general X-Git-Tag: OPENLDAP_REL_ENG_2_BP~251 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2fda53f375b1daa46d8ae259d5fc6ba667ed4f5c;p=openldap Add missing arguments to Debug() calls... and adapt nt_debug for general use. --- diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 3c8bfe4386..f8a45f357b 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -329,6 +329,7 @@ slapd_daemon_task( while ( !slapd_shutdown ) { ber_socket_t i; int ns; + int at; ber_socket_t nfds; #define SLAPD_EBADF_LIMIT 10 int ebadf = 0; @@ -391,21 +392,31 @@ slapd_daemon_task( ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_lock( &active_threads_mutex ); + at = active_threads; + ldap_pvt_thread_mutex_unlock( &active_threads_mutex ); + #if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS ) tvp = NULL; #else - tvp = active_threads ? &zero : NULL; + tvp = at ? &zero : NULL; #endif Debug( LDAP_DEBUG_CONNS, "daemon: select: tcps=%d active_threads=%d tvp=%s\n", - tcps, active_threads, + tcps, at, tvp == NULL ? "NULL" : "zero" ); - ldap_pvt_thread_mutex_unlock( &active_threads_mutex ); - switch(ns = select( nfds, &readfds, &writefds, 0, tvp )) { + switch(ns = select( nfds, &readfds, +#ifdef HAVE_WINSOCK + /* don't pass empty fd_set */ + ( writefds.fd_count > 0 ? &writefds : NULL ), +#else + &writefds, +#endif + NULL, tvp )) + { case -1: { /* failure - try again */ #ifdef HAVE_WINSOCK int err = WSAGetLastError(); @@ -561,10 +572,12 @@ slapd_daemon_task( Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 ); #ifdef HAVE_WINSOCK for ( i = 0; i < readfds.fd_count; i++ ) { - Debug( LDAP_DEBUG_CONNS, " %d%s", readfds.fd_array[i], "r" ); + Debug( LDAP_DEBUG_CONNS, " %d%s", + readfds.fd_array[i], "r", 0 ); } for ( i = 0; i < writefds.fd_count; i++ ) { - Debug( LDAP_DEBUG_CONNS, " %d%s", writefds.fd_array[i], "w" ); + Debug( LDAP_DEBUG_CONNS, " %d%s", + writefds.fd_array[i], "w", 0 ); } #else for ( i = 0; i < nfds; i++ ) { @@ -784,7 +797,8 @@ void hit_socket() if ( connect( s, (struct sockaddr *)&bind_addr, sizeof( struct sockaddr_in )) == SOCKET_ERROR ) { Debug( LDAP_DEBUG_ANY, - "hit_socket: error on connect: %d\n", WSAGetLastError(), 0 ); + "hit_socket: error on connect: %d\n", + WSAGetLastError(), 0, 0 ); /* we can probably expect some error to occur here, mostly WSAEWOULDBLOCK */ } @@ -815,7 +829,7 @@ slap_set_shutdown( int sig ) ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 ); } #else - Debug( LDAP_DEBUG_TRACE, "Shutdown %d ordered", sig, 0 ); + Debug( LDAP_DEBUG_TRACE, "Shutdown %d ordered", sig, 0, 0 ); /* trying to "hit" the socket seems to always get a */ /* EWOULDBLOCK error, so just close the listen socket to */ /* break out of the select since we're shutting down anyway */ diff --git a/servers/slapd/nt_debug.c b/servers/slapd/nt_debug.c index b4a650fc55..fc9027cbf5 100644 --- a/servers/slapd/nt_debug.c +++ b/servers/slapd/nt_debug.c @@ -11,14 +11,22 @@ static FILE *log_file; -void (Debug)( int level, const char *fmt, ... ) +int lutil_debug_file( FILE *file ) +{ + log_file = log_file; + + return 0; +} + +void (lutil_debug)( int level, int debug, const char *fmt, ... ) { char buffer[4096]; va_list vl; - if ( !(level & ldap_debug ) ) + if ( !(level & debug ) ) return; +#ifdef HAVE_WINSOCK if( log_file == NULL ) { log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "slapd.log", "w" ); @@ -29,13 +37,18 @@ void (Debug)( int level, const char *fmt, ... ) if ( log_file == NULL ) return; } +#endif va_start( vl, fmt ); - vsprintf( buffer, fmt, vl ); - fprintf( log_file, "%s", buffer ); - printf ("%s", buffer); + vsnprintf( buffer, sizeof(buffer), fmt, vl ); + buffer[sizeof(buffer)-1] = '\0'; + + if( log_file != NULL ) { + fputs( buffer, log_file ); + fflush( log_file ); + } - fflush( log_file ); + puts(buffer ); va_end( vl ); }