X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fmonitor.c;h=a7311989ef4fb086ed8541a5d238e74307f941cc;hb=76ed17f7942d4e3810fa90b46143e615af311167;hp=7dbabc93772c071c9c180645aa8cbef8b251227f;hpb=58ea169c92679eb5b0598c2420c95c626ccac27d;p=openldap diff --git a/servers/slapd/monitor.c b/servers/slapd/monitor.c index 7dbabc9377..a7311989ef 100644 --- a/servers/slapd/monitor.c +++ b/servers/slapd/monitor.c @@ -10,8 +10,16 @@ * 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 #include +#include #include #include #include "slap.h" @@ -32,18 +40,16 @@ extern time_t currenttime; 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 ) { Entry *e; - char buf[BUFSIZ], buf2[20]; + char buf[BUFSIZ], buf2[22]; struct berval val; struct berval *vals[2]; int i, nconns, nwritewaiters, nreadwaiters; @@ -54,6 +60,8 @@ monitor_info( Connection *conn, Operation *op ) 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 ); @@ -73,6 +81,8 @@ monitor_info( Connection *conn, Operation *op ) 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++; @@ -82,8 +92,15 @@ monitor_info( Connection *conn, Operation *op ) if ( c[i].c_gettingber ) { nreadwaiters++; } + pthread_mutex_lock( ¤ttime_mutex ); ltm = localtime( &c[i].c_starttime ); +#ifdef LDAP_Y2K + strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm ); +#else 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, buf2, c[i].c_opsinitiated, c[i].c_opscompleted, @@ -96,6 +113,8 @@ monitor_info( Connection *conn, Operation *op ) attr_merge( e, "connection", vals ); } } + pthread_mutex_unlock( &new_conn_mutex ); + sprintf( buf, "%d", nconns ); val.bv_val = buf; val.bv_len = strlen( buf ); @@ -141,14 +160,26 @@ monitor_info( Connection *conn, Operation *op ) 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 ); + ltm = localtime( ¤ttime ); +#ifdef LDAP_Y2K + strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm ); +#else + 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 ); + ltm = localtime( &starttime ); +#ifdef LDAP_Y2K + strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm ); +#else + 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 );