* 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"
extern time_t starttime;
extern int num_conns;
+extern pthread_mutex_t new_conn_mutex;
+extern pthread_mutex_t currenttime_mutex;
extern char Versionstr[];
-/*
- * no mutex protection in here - take our chances!
- */
-
void
monitor_info( Connection *conn, Operation *op )
{
vals[1] = NULL;
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
+ /* initialize reader/writer lock */
+ pthread_rdwr_init_np(&e->e_rdwr, NULL);
e->e_attrs = NULL;
e->e_dn = strdup( SLAPD_MONITOR_DN );
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++;
if ( c[i].c_gettingber ) {
nreadwaiters++;
}
+ pthread_mutex_lock( ¤ttime_mutex );
ltm = localtime( &c[i].c_starttime );
strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
+ pthread_mutex_unlock( ¤ttime_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,
attr_merge( e, "connection", vals );
}
}
+ pthread_mutex_unlock( &new_conn_mutex );
+
sprintf( buf, "%d", nconns );
val.bv_val = buf;
val.bv_len = strlen( buf );
val.bv_len = strlen( buf );
attr_merge( e, "bytessent", vals );
+ pthread_mutex_lock( ¤ttime_mutex );
ltm = localtime( ¤ttime );
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+ pthread_mutex_unlock( ¤ttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currenttime", vals );
+ pthread_mutex_lock( ¤ttime_mutex );
ltm = localtime( &starttime );
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+ pthread_mutex_unlock( ¤ttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "starttime", vals );