slapd 3.3 bug fixes

Jeff.Hodges@stanford.edu
Fri, 14 Jun 96 12:51:53 -0700

These patches to slapd (below) fix some thread-associated bugs I discovered.
I've already submitted them to ldap-support; I'm posting them here so that
folks who need 'em can get 'em now. The ldap-support folks are collecting up
various fixes and will include them in an overall release sometime in the
future.

These particular bugs manifest themselves when slapd is handling > 1 client
and/or the "cn=monitor" entry is being retrieved.

With these patches applied, I've pounded slapd with 15+ flat-out clients
simultaenously for > a day (retrieved 1.7M entries) successfully.

Jeff
---------------------------------------------------------------------------
*** daemon.c Thu Jun 6 12:03:00 1996
--- daemon.c.orig Thu May 30 12:39:16 1996
***************
*** 1,10 ****
-
- /* Revision history
- *
- * 5-Jun-96 hodges
- * Added locking of new_conn_mutex when traversing the c[] array.
- */
-
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
--- 1,3 ----
***************
*** 171,178 ****
Debug( LDAP_DEBUG_CONNS,
"listening for connections on %d, activity on:",
tcps, 0, 0 );
-
- pthread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) {
if ( c[i].c_sb.sb_sd != -1 ) {
FD_SET( c[i].c_sb.sb_sd, &readfds );
--- 164,169 ----
***************
*** 185,191 ****
}
}
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
- pthread_mutex_unlock( &new_conn_mutex );

zero.tv_sec = 0;
zero.tv_usec = 0;
--- 176,181 ----
*** monitor.c Mon Jun 10 09:22:44 1996
--- monitor.c.orig Wed Jun 5 10:28:35 1996
***************
*** 10,25 ****
* is provided ``as is'' without express or implied warranty.
*/

- /* Revision history
- *
- * 5-Jun-96 jeff.hodges@stanford.edu
- * Added locking of new_conn_mutex when traversing the c[] array.
- * Added locking of currenttime_mutex to protect call(s) to localtime().
- */
-
#include <stdio.h>
#include <string.h>
- #include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "slap.h"
--- 10,17 ----
***************
*** 40,50 ****
extern time_t starttime;
extern int num_conns;

- extern pthread_mutex_t new_conn_mutex;
- extern pthread_mutex_t currenttime_mutex;

extern char Versionstr[];

void
monitor_info( Connection *conn, Operation *op )
{
--- 32,44 ----
extern time_t starttime;
extern int num_conns;


extern char Versionstr[];

+ /*
+ * no mutex protection in here - take our chances!
+ */
+
void
monitor_info( Connection *conn, Operation *op )
{
***************
*** 79,86 ****
nconns = 0;
nwritewaiters = 0;
nreadwaiters = 0;
-
- pthread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) {
if ( c[i].c_sb.sb_sd != -1 ) {
nconns++;
--- 73,78 ----
***************
*** 90,100 ****
if ( c[i].c_gettingber ) {
nreadwaiters++;
}
- pthread_mutex_lock( &currenttime_mutex );
ltm = localtime( &c[i].c_starttime );
strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
- pthread_mutex_unlock( &currenttime_mutex );
-
pthread_mutex_lock( &c[i].c_dnmutex );
sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
--- 82,89 ----
***************
*** 107,114 ****
attr_merge( e, "connection", vals );
}
}
- pthread_mutex_unlock( &new_conn_mutex );
-
sprintf( buf, "%d", nconns );
val.bv_val = buf;
val.bv_len = strlen( buf );
--- 96,101 ----
***************
*** 154,171 ****
val.bv_len = strlen( buf );
attr_merge( e, "bytessent", vals );

- pthread_mutex_lock( &currenttime_mutex );
ltm = localtime( &currenttime );
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
- pthread_mutex_unlock( &currenttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currenttime", vals );

- pthread_mutex_lock( &currenttime_mutex );
ltm = localtime( &starttime );
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
- pthread_mutex_unlock( &currenttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "starttime", vals );
--- 141,154 ----