* is provided ``as is'' without express or implied warranty.
*/
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
-#include "ldapconfig.h"
+/* 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().
+ */
-#if defined( SLAPD_MONITOR_DN )
+#include "portable.h"
-extern int nbackends;
-extern Backend *backends;
-extern int active_threads;
-extern int dtblsize;
-extern Connection *c;
-extern long ops_initiated;
-extern long ops_completed;
-extern long num_entries_sent;
-extern long num_bytes_sent;
-extern time_t currenttime;
-extern time_t starttime;
-extern int num_conns;
+#include <stdio.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
-extern char Versionstr[];
+#include "ldapconfig.h"
+#include "slap.h"
-/*
- * no mutex protection in here - take our chances!
- */
+#if defined( SLAPD_MONITOR_DN )
void
monitor_info( Connection *conn, Operation *op )
{
Entry *e;
- char buf[BUFSIZ], buf2[20];
+ char buf[BUFSIZ], buf2[22];
struct berval val;
struct berval *vals[2];
int i, nconns, nwritewaiters, nreadwaiters;
vals[1] = NULL;
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
+ /* initialize reader/writer lock */
+ entry_rdwr_init(e);
e->e_attrs = NULL;
- e->e_dn = strdup( SLAPD_MONITOR_DN );
+ e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
val.bv_val = Versionstr;
if (( p = strchr( Versionstr, '\n' )) == NULL ) {
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 );
+#ifndef LDAP_LOCALTIME
+ ltm = gmtime( &c[i].c_starttime );
+ strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
+#else
ltm = localtime( &c[i].c_starttime );
strftime( buf2, sizeof(buf2), "%y%m%d%H%M%SZ", ltm );
+#endif
+ pthread_mutex_unlock( ¤ttime_mutex );
+
pthread_mutex_lock( &c[i].c_dnmutex );
- sprintf( buf, "%d : %s : %ld : %ld : %s : %s%s", i,
+ sprintf( buf, "%d : %s : %d : %d : %s : %s%s", i,
buf2, c[i].c_opsinitiated, c[i].c_opscompleted,
c[i].c_dn ? c[i].c_dn : "NULLDN",
c[i].c_gettingber ? "r" : "",
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 );
- ltm = localtime( ¤ttime );
- strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+ pthread_mutex_lock( ¤ttime_mutex );
+#ifndef LDAP_LOCALTIME
+ ltm = gmtime( ¤ttime );
+ strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
+#else
+ ltm = localtime( ¤ttime );
+ strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+#endif
+ pthread_mutex_unlock( ¤ttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currenttime", vals );
- ltm = localtime( &starttime );
- strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+ pthread_mutex_lock( ¤ttime_mutex );
+#ifndef LDAP_LOCALTIME
+ ltm = gmtime( &starttime );
+ strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
+#else
+ ltm = localtime( &starttime );
+ strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+#endif
+ pthread_mutex_unlock( ¤ttime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "starttime", vals );
val.bv_len = strlen( buf );
attr_merge( e, "nbackends", vals );
-#ifdef THREAD_SUNOS5_LWP
+#ifdef HAVE_THR
sprintf( buf, "%d", thr_getconcurrency() );
val.bv_val = buf;
val.bv_len = strlen( buf );