From 55e251e6e83840d33afa500098a61f140ec258fd Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 12 Sep 2004 22:12:58 +0000 Subject: [PATCH] lots of cleanup; few improvements; fix RDN selection bug when creating connection dynamic entries; rework entries ordering - now it's more intuitive and regular; optimize counters update --- servers/slapd/back-monitor/README | 112 ++++--- servers/slapd/back-monitor/back-monitor.h | 112 +++---- servers/slapd/back-monitor/backend.c | 37 ++- servers/slapd/back-monitor/cache.c | 17 +- servers/slapd/back-monitor/conn.c | 154 ++++----- servers/slapd/back-monitor/database.c | 40 ++- servers/slapd/back-monitor/init.c | 298 +++++++++--------- servers/slapd/back-monitor/listener.c | 43 ++- servers/slapd/back-monitor/log.c | 6 +- servers/slapd/back-monitor/operation.c | 94 +++--- servers/slapd/back-monitor/overlay.c | 36 +-- .../slapd/back-monitor/proto-back-monitor.h | 33 ++ servers/slapd/back-monitor/rww.c | 32 +- servers/slapd/back-monitor/search.c | 2 +- servers/slapd/back-monitor/sent.c | 49 +-- servers/slapd/back-monitor/thread.c | 155 +++++++-- servers/slapd/back-monitor/time.c | 55 ++-- servers/slapd/connection.c | 18 +- 18 files changed, 699 insertions(+), 594 deletions(-) diff --git a/servers/slapd/back-monitor/README b/servers/slapd/back-monitor/README index dc1d9f72df..21d7b868f2 100644 --- a/servers/slapd/back-monitor/README +++ b/servers/slapd/back-monitor/README @@ -20,7 +20,7 @@ configure directive The suffix "cn=Monitor" is implicitly activated (it cannot be given as a suffix of the database as usually done for conventional backends). Note that the "cn=Monitor" naming context appears in the rootDSE -(FIXME: do we really want this?) +in the attribute monitorContext A bind operation is provided; at present it allows to bind as the backend rootdn. As a result, the backend supports the rootdn/rootpw @@ -81,34 +81,19 @@ partially useful information is provided. The subsystems are: - Listener - Databases Backends - Threads - SASL - TLS Connections - Read Waiters - Write Waiters + Databases + Listener Log Operations + Overlays + SASL Statistics + Threads Time - - - -LISTENER SUBSYSTEM - -It contains the description of the devices the server is currently -listening on - - - -DATABASES SUBSYSTEM - -The main entry contains the naming context of each configured database; -the subentries contain, for each database, the type and the naming -context. + TLS + Read/Write Waiters @@ -121,25 +106,6 @@ backends are enabled. -THREADS SUBSYSTEM - -It contains the maximum number of threads enabled at startup and the -current backload. - - - -SASL - -Currently empty. - - - -TLS - -Currently empty. - - - CONNECTIONS The main entry is empty; it should contain some statistics on the number @@ -151,15 +117,18 @@ current connections respectively. -READ WAITERS SUBSYSTEM +DATABASES SUBSYSTEM -It contains the number of current read waiters. +The main entry contains the naming context of each configured database; +the subentries contain, for each database, the type and the naming +context. -WRITE WAITERS SUBSYSTEM +LISTENER SUBSYSTEM -It contains the number of current write waiters. +It contains the description of the devices the server is currently +listening on @@ -196,16 +165,51 @@ It shows some statistics on the operations performed by the server: Initiated Completed +and for each operation type, i.e.: + + Bind + Unbind + Add + Delete + Modrdn + Modify + Compare + Search + Abandon + Extended + + + +OVERLAYS SUBSYSTEM + +The main entry contains the type of overlays available at run-time; +the subentries, for each overlay, contain the type of the overlay. +It should also contain the modules that have been loaded if dynamic +overlays are enabled. + + + +SASL + +Currently empty. + -SENT SUBSYSTEM +STATISTICS SUBSYSTEM It shows some statistics on the data sent by the server: Bytes PDU - Referrals Entries + Referrals + + + +THREADS SUBSYSTEM + +It contains the maximum number of threads enabled at startup and the +current backload. @@ -216,6 +220,18 @@ of the server. +TLS + +Currently empty. + + + +READ/WRITE WAITERS SUBSYSTEM + +It contains the number of current read waiters. + + + NOTES This document is in a very early stage of maturity and will diff --git a/servers/slapd/back-monitor/back-monitor.h b/servers/slapd/back-monitor/back-monitor.h index 3a41b59b11..1f6a030ba8 100644 --- a/servers/slapd/back-monitor/back-monitor.h +++ b/servers/slapd/back-monitor/back-monitor.h @@ -112,101 +112,105 @@ struct monitorinfo { * DNs */ -#define SLAPD_MONITOR_AT "cn" - -#define SLAPD_MONITOR_LISTENER 0 -#define SLAPD_MONITOR_LISTENER_NAME "Listeners" -#define SLAPD_MONITOR_LISTENER_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LISTENER_NAME -#define SLAPD_MONITOR_LISTENER_DN \ - SLAPD_MONITOR_LISTENER_RDN "," SLAPD_MONITOR_DN +enum { + SLAPD_MONITOR_BACKEND = 0, + SLAPD_MONITOR_CONN, + SLAPD_MONITOR_DATABASE, + SLAPD_MONITOR_LISTENER, + SLAPD_MONITOR_LOG, + SLAPD_MONITOR_OPS, + SLAPD_MONITOR_OVERLAY, + SLAPD_MONITOR_SASL, + SLAPD_MONITOR_SENT, + SLAPD_MONITOR_THREAD, + SLAPD_MONITOR_TIME, + SLAPD_MONITOR_TLS, + SLAPD_MONITOR_RWW, + + SLAPD_MONITOR_LAST +}; -#define SLAPD_MONITOR_DATABASE 1 -#define SLAPD_MONITOR_DATABASE_NAME "Databases" -#define SLAPD_MONITOR_DATABASE_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_DATABASE_NAME -#define SLAPD_MONITOR_DATABASE_DN \ - SLAPD_MONITOR_DATABASE_RDN "," SLAPD_MONITOR_DN +#define SLAPD_MONITOR_AT "cn" -#define SLAPD_MONITOR_BACKEND 2 #define SLAPD_MONITOR_BACKEND_NAME "Backends" #define SLAPD_MONITOR_BACKEND_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_BACKEND_NAME #define SLAPD_MONITOR_BACKEND_DN \ SLAPD_MONITOR_BACKEND_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_THREAD 3 -#define SLAPD_MONITOR_THREAD_NAME "Threads" -#define SLAPD_MONITOR_THREAD_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_THREAD_NAME -#define SLAPD_MONITOR_THREAD_DN \ - SLAPD_MONITOR_THREAD_RDN "," SLAPD_MONITOR_DN - -#define SLAPD_MONITOR_SASL 4 -#define SLAPD_MONITOR_SASL_NAME "SASL" -#define SLAPD_MONITOR_SASL_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SASL_NAME -#define SLAPD_MONITOR_SASL_DN \ - SLAPD_MONITOR_SASL_RDN "," SLAPD_MONITOR_DN - -#define SLAPD_MONITOR_TLS 5 -#define SLAPD_MONITOR_TLS_NAME "TLS" -#define SLAPD_MONITOR_TLS_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TLS_NAME -#define SLAPD_MONITOR_TLS_DN \ - SLAPD_MONITOR_TLS_RDN "," SLAPD_MONITOR_DN - -#define SLAPD_MONITOR_CONN 6 #define SLAPD_MONITOR_CONN_NAME "Connections" #define SLAPD_MONITOR_CONN_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_CONN_NAME #define SLAPD_MONITOR_CONN_DN \ SLAPD_MONITOR_CONN_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_RWW 7 -#define SLAPD_MONITOR_RWW_NAME "Waiters" -#define SLAPD_MONITOR_RWW_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_RWW_NAME -#define SLAPD_MONITOR_RWW_DN \ - SLAPD_MONITOR_RWW_RDN "," SLAPD_MONITOR_DN +#define SLAPD_MONITOR_DATABASE_NAME "Databases" +#define SLAPD_MONITOR_DATABASE_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_DATABASE_NAME +#define SLAPD_MONITOR_DATABASE_DN \ + SLAPD_MONITOR_DATABASE_RDN "," SLAPD_MONITOR_DN + +#define SLAPD_MONITOR_LISTENER_NAME "Listeners" +#define SLAPD_MONITOR_LISTENER_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LISTENER_NAME +#define SLAPD_MONITOR_LISTENER_DN \ + SLAPD_MONITOR_LISTENER_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_LOG 8 #define SLAPD_MONITOR_LOG_NAME "Log" #define SLAPD_MONITOR_LOG_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LOG_NAME #define SLAPD_MONITOR_LOG_DN \ SLAPD_MONITOR_LOG_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_OPS 9 #define SLAPD_MONITOR_OPS_NAME "Operations" #define SLAPD_MONITOR_OPS_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OPS_NAME #define SLAPD_MONITOR_OPS_DN \ SLAPD_MONITOR_OPS_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_SENT 10 +#define SLAPD_MONITOR_OVERLAY_NAME "Overlay" +#define SLAPD_MONITOR_OVERLAY_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OVERLAY_NAME +#define SLAPD_MONITOR_OVERLAY_DN \ + SLAPD_MONITOR_OVERLAY_RDN "," SLAPD_MONITOR_DN + +#define SLAPD_MONITOR_SASL_NAME "SASL" +#define SLAPD_MONITOR_SASL_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SASL_NAME +#define SLAPD_MONITOR_SASL_DN \ + SLAPD_MONITOR_SASL_RDN "," SLAPD_MONITOR_DN + #define SLAPD_MONITOR_SENT_NAME "Statistics" #define SLAPD_MONITOR_SENT_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SENT_NAME #define SLAPD_MONITOR_SENT_DN \ SLAPD_MONITOR_SENT_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_TIME 11 +#define SLAPD_MONITOR_THREAD_NAME "Threads" +#define SLAPD_MONITOR_THREAD_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_THREAD_NAME +#define SLAPD_MONITOR_THREAD_DN \ + SLAPD_MONITOR_THREAD_RDN "," SLAPD_MONITOR_DN + #define SLAPD_MONITOR_TIME_NAME "Time" #define SLAPD_MONITOR_TIME_RDN \ SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TIME_NAME #define SLAPD_MONITOR_TIME_DN \ SLAPD_MONITOR_TIME_RDN "," SLAPD_MONITOR_DN -#define SLAPD_MONITOR_OVERLAY 12 -#define SLAPD_MONITOR_OVERLAY_NAME "Overlay" -#define SLAPD_MONITOR_OVERLAY_RDN \ - SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OVERLAY_NAME -#define SLAPD_MONITOR_OVERLAY_DN \ - SLAPD_MONITOR_OVERLAY_RDN "," SLAPD_MONITOR_DN +#define SLAPD_MONITOR_TLS_NAME "TLS" +#define SLAPD_MONITOR_TLS_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TLS_NAME +#define SLAPD_MONITOR_TLS_DN \ + SLAPD_MONITOR_TLS_RDN "," SLAPD_MONITOR_DN + +#define SLAPD_MONITOR_RWW_NAME "Waiters" +#define SLAPD_MONITOR_RWW_RDN \ + SLAPD_MONITOR_AT "=" SLAPD_MONITOR_RWW_NAME +#define SLAPD_MONITOR_RWW_DN \ + SLAPD_MONITOR_RWW_RDN "," SLAPD_MONITOR_DN struct monitorsubsys { - int mss_type; char *mss_name; struct berval mss_rdn; struct berval mss_dn; diff --git a/servers/slapd/back-monitor/backend.c b/servers/slapd/back-monitor/backend.c index 8b1fe4d1c9..c0c61b95fe 100644 --- a/servers/slapd/back-monitor/backend.c +++ b/servers/slapd/back-monitor/backend.c @@ -37,7 +37,7 @@ monitor_subsys_backend_init( ) { struct monitorinfo *mi; - Entry *e, *e_backend, *e_tmp; + Entry *e_backend, **ep; int i; struct monitorentrypriv *mp; @@ -45,21 +45,25 @@ monitor_subsys_backend_init( if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, - &e_backend ) ) { + &e_backend ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_backend_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; - for ( i = nBackendInfo; i--; ) { + mp = ( struct monitorentrypriv * )e_backend->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + + for ( i = 0; i < nBackendInfo; i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; BackendInfo *bi; struct berval bv; int j; + Entry *e; bi = &backendInfo[i]; @@ -86,10 +90,8 @@ monitor_subsys_backend_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_backend_init: " - "unable to create entry 'cn=Backend %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, - "" ); + "unable to create entry \"cn=Backend %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 ); return( -1 ); } @@ -131,7 +133,7 @@ monitor_subsys_backend_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags @@ -140,19 +142,16 @@ monitor_subsys_backend_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_backend_init: " - "unable to add entry 'cn=Backend %d,%s'\n%s", + "unable to add entry \"cn=Backend %d,%s\"\n", i, - monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, - "" ); + monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_backend->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_backend ); return( 0 ); diff --git a/servers/slapd/back-monitor/cache.c b/servers/slapd/back-monitor/cache.c index ea2c8e4798..dd7086725c 100644 --- a/servers/slapd/back-monitor/cache.c +++ b/servers/slapd/back-monitor/cache.c @@ -22,6 +22,7 @@ #include "portable.h" #include +#include "ac/string.h" #include "slap.h" @@ -165,7 +166,7 @@ monitor_cache_dn2entry( { struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private; int rc; - struct berval p_ndn = { 0L, NULL }; + struct berval p_ndn = BER_BVNULL; Entry *e_parent; struct monitorentrypriv *mp; @@ -182,21 +183,15 @@ monitor_cache_dn2entry( } /* try with parent/ancestors */ - if ( ndn->bv_len ) { - dnParent( ndn, &p_ndn ); - } + if ( BER_BVISNULL( ndn ) ) { + BER_BVSTR( &p_ndn, "" ); - if ( p_ndn.bv_val == NULL ) { - p_ndn.bv_val = ""; - p_ndn.bv_len = 0; - } else { - p_ndn.bv_len = ndn->bv_len - - ( ber_len_t ) ( p_ndn.bv_val - ndn->bv_val ); + dnParent( ndn, &p_ndn ); } rc = monitor_cache_dn2entry( op, &p_ndn, &e_parent, matched ); - if ( rc || e_parent == NULL) { + if ( rc || e_parent == NULL ) { return( -1 ); } diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index 64076993fe..ce61417eb4 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -28,8 +28,6 @@ #include "lutil.h" #include "back-monitor.h" -#define CONN_CN_PREFIX "Connection" - int monitor_subsys_conn_init( BackendDB *be @@ -37,7 +35,7 @@ monitor_subsys_conn_init( { struct monitorinfo *mi; - Entry *e, *e_tmp, *e_conn; + Entry *e, **ep, *e_conn; struct monitorentrypriv *mp; char buf[ BACKMONITOR_BUFSIZE ]; struct berval bv; @@ -47,16 +45,18 @@ monitor_subsys_conn_init( mi = ( struct monitorinfo * )be->be_private; if ( monitor_cache_get( mi, - &monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) { + &monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_conn->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; /* * Total conns @@ -82,19 +82,17 @@ monitor_subsys_conn_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_init: " - "unable to create entry 'cn=Total,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, - "", "" ); + "unable to create entry \"cn=Total,%s\"\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - bv.bv_val = "0"; - bv.bv_len = 1; + BER_BVSTR( &bv, "0" ); attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL ); mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \ @@ -104,14 +102,14 @@ monitor_subsys_conn_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_init: " - "unable to add entry 'cn=Total,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, - "", "" ); + "unable to add entry \"cn=Total,%s\"\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - - e_tmp = e; + *ep = e; + ep = &mp->mp_next; + /* * Current conns */ @@ -136,19 +134,17 @@ monitor_subsys_conn_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_init: " - "unable to create entry 'cn=Current,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, - "", "" ); + "unable to create entry \"cn=Current,%s\"\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - bv.bv_val = "0"; - bv.bv_len = 1; + BER_BVSTR( &bv, "0" ); attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL ); mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \ @@ -158,16 +154,13 @@ monitor_subsys_conn_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_init: " - "unable to add entry 'cn=Current,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, - "", "" ); + "unable to add entry \"cn=Current,%s\"\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = e; - - mp = ( struct monitorentrypriv * )e_conn->e_private; - mp->mp_children = e_tmp; + *ep = e; + ep = &mp->mp_next; monitor_cache_release( mi, e_conn ); @@ -180,18 +173,23 @@ monitor_subsys_conn_update( Entry *e ) { - struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private; - long n = -1; + struct monitorinfo *mi = + (struct monitorinfo *)op->o_bd->be_private; + + long n = -1; + static struct berval total_bv = BER_BVC( "cn=total" ), + current_bv = BER_BVC( "cn=current" ); + struct berval rdn; assert( mi ); assert( e ); + + dnRdn( &e->e_nname, &rdn ); - if ( strncasecmp( e->e_ndn, "cn=total", - sizeof("cn=total")-1 ) == 0 ) { + if ( dn_match( &rdn, &total_bv ) ) { n = connections_nextid(); - } else if ( strncasecmp( e->e_ndn, "cn=current", - sizeof("cn=current")-1 ) == 0 ) { + } else if ( dn_match( &rdn, ¤t_bv ) ) { Connection *c; int connindex; @@ -200,12 +198,13 @@ monitor_subsys_conn_update( n++, c = connection_next( c, &connindex ) ) { /* No Op */ ; } - connection_done(c); + connection_done( c ); } if ( n != -1 ) { Attribute *a; char buf[] = "+9223372036854775807L"; + ber_len_t len; a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter ); if ( a == NULL ) { @@ -213,8 +212,12 @@ monitor_subsys_conn_update( } snprintf( buf, sizeof( buf ), "%ld", n ); - free( a->a_vals[ 0 ].bv_val ); - ber_str2bv( buf, 0, 1, a->a_vals ); + len = strlen( buf ); + if ( len > a->a_vals[ 0 ].bv_len ) { + a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 ); + } + a->a_vals[ 0 ].bv_len = len; + AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 ); } return( 0 ); @@ -281,10 +284,10 @@ conn_create( #endif snprintf( buf, sizeof( buf ), - "dn: cn=" CONN_CN_PREFIX " %ld,%s\n" + "dn: cn=Connection %ld,%s\n" "objectClass: %s\n" "structuralObjectClass: %s\n" - "cn: " CONN_CN_PREFIX " %ld\n" + "cn: Connection %ld\n" "creatorsName: %s\n" "modifiersName: %s\n" "createTimestamp: %s\n" @@ -304,7 +307,7 @@ conn_create( Debug( LDAP_DEBUG_ANY, "monitor_subsys_conn_create: " "unable to create entry " - "'cn=" CONN_CN_PREFIX " %ld,%s' entry\n", + "\"cn=Connection %ld,%s\" entry\n", c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val, 0 ); return( -1 ); @@ -334,16 +337,22 @@ conn_create( /* monitored info */ sprintf( buf, - "%ld : %ld " + "%ld " + ": %ld " ": %ld/%ld/%ld/%ld " ": %ld/%ld/%ld " ": %s%s%s%s%s%s " - ": %s : %s : %s " - ": %s : %s : %s : %s", + ": %s " + ": %s " + ": %s " + ": %s " + ": %s " + ": %s " + ": %s", c->c_connid, (long) c->c_protocol, c->c_n_ops_received, c->c_n_ops_executing, - c->c_n_ops_pending, c->c_n_ops_completed, + c->c_n_ops_pending, c->c_n_ops_completed, /* add low-level counters here */ c->c_n_get, c->c_n_read, c->c_n_write, @@ -407,10 +416,13 @@ monitor_subsys_conn_create( Entry **ep ) { - struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private; + struct monitorinfo *mi = + (struct monitorinfo *)op->o_bd->be_private; + Connection *c; int connindex; struct monitorentrypriv *mp; + int rc = 0; assert( mi != NULL ); assert( e_parent != NULL ); @@ -419,14 +431,14 @@ monitor_subsys_conn_create( *ep = NULL; if ( ndn == NULL ) { - Entry *e, *e_tmp = NULL; + Entry *e = NULL, + *e_tmp = NULL; /* create all the children of e_parent */ for ( c = connection_first( &connindex ); c != NULL; c = connection_next( c, &connindex )) { if ( conn_create( mi, c, &e ) || e == NULL ) { - connection_done(c); for ( ; e_tmp != NULL; ) { mp = ( struct monitorentrypriv * )e_tmp->e_private; e = mp->mp_next; @@ -437,44 +449,43 @@ monitor_subsys_conn_create( e_tmp = e; } - return( -1 ); + rc = -1; + break; } mp = ( struct monitorentrypriv * )e->e_private; mp->mp_next = e_tmp; e_tmp = e; } connection_done(c); - *ep = e; } else { - LDAPRDN values = NULL; - const char *text = NULL; - unsigned long connid; - - /* create exactly the required entry */ + unsigned long connid; + char *next = NULL; + static struct berval nconn_bv = BER_BVC( "cn=connection " ); - if ( ldap_bv2rdn( ndn, &values, (char **)&text, - LDAP_DN_FORMAT_LDAP ) ) + + /* create exactly the required entry; + * the normalized DN must start with "cn=connection ", + * followed by the connection id, followed by + * the RDN separator "," */ + if ( ndn->bv_len <= nconn_bv.bv_len + || strncmp( ndn->bv_val, nconn_bv.bv_val, nconn_bv.bv_len ) != 0 ) { - return( -1 ); + return -1; } - assert( values ); - assert( values[ 0 ] ); - - connid = atol( values[ 0 ]->la_value.bv_val - + sizeof( CONN_CN_PREFIX ) ); - - ldap_rdnfree( values ); + connid = strtol( &ndn->bv_val[ nconn_bv.bv_len ], &next, 10 ); + if ( next[ 0 ] != ',' ) { + return -1; + } for ( c = connection_first( &connindex ); c != NULL; c = connection_next( c, &connindex )) { if ( c->c_connid == connid ) { if ( conn_create( mi, c, ep ) || *ep == NULL ) { - connection_done( c ); - return( -1 ); + rc = -1; } break; @@ -482,9 +493,8 @@ monitor_subsys_conn_create( } connection_done(c); - } - return( 0 ); + return rc; } diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index ffe4308bc5..e304c09e45 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -100,7 +100,7 @@ monitor_subsys_database_init( ) { struct monitorinfo *mi; - Entry *e, *e_database, *e_tmp; + Entry *e_database, **ep; int i; struct monitorentrypriv *mp; @@ -110,24 +110,28 @@ monitor_subsys_database_init( if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn, - &e_database ) ) { + &e_database ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_database_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 ); return( -1 ); } (void)init_readOnly( mi, e_database, frontendDB->be_restrictops ); (void)init_restrictedOperation( mi, e_database, frontendDB->be_restrictops ); - e_tmp = NULL; - for ( i = nBackendDB; i--; ) { + mp = ( struct monitorentrypriv * )e_database->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + + for ( i = 0; i < nBackendDB; i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; int j; slap_overinfo *oi = NULL; BackendInfo *bi; + Entry *e; be = &backendDB[i]; @@ -170,10 +174,8 @@ monitor_subsys_database_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_database_init: " - "unable to create entry 'cn=Database %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, - "" ); + "unable to create entry \"cn=Database %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 ); return( -1 ); } @@ -233,7 +235,7 @@ monitor_subsys_database_init( } #endif /* defined(SLAPD_LDAP) */ - for ( j = nBackendInfo; j--; ) { + for ( j = 0; j < nBackendInfo; j++ ) { if ( backendInfo[ j ].bi_type == bi->bi_type ) { struct berval bv; @@ -252,7 +254,7 @@ monitor_subsys_database_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags @@ -261,10 +263,8 @@ monitor_subsys_database_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_database_init: " - "unable to add entry 'cn=Database %d,%s'\n", - i, - monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, - 0 ); + "unable to add entry \"cn=Database %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 ); return( -1 ); } @@ -272,12 +272,10 @@ monitor_subsys_database_init( monitor_back_add_plugin( be, e ); #endif /* defined(LDAP_SLAPI) */ - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_database->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_database ); return( 0 ); diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 0be50d800b..c06e4d9eb1 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -41,23 +41,7 @@ BackendDB *be_monitor = NULL; */ struct monitorsubsys monitor_subsys[] = { { - SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME, - BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_PERSISTENT_CH, - monitor_subsys_listener_init, - NULL, /* update */ - NULL, /* create */ - NULL /* modify */ - }, { - SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME, - BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_PERSISTENT_CH, - monitor_subsys_database_init, - NULL, /* update */ - NULL, /* create */ - monitor_subsys_database_modify - }, { - SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME, + SLAPD_MONITOR_BACKEND_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_PERSISTENT_CH, monitor_subsys_backend_init, @@ -65,31 +49,7 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* create */ NULL /* modify */ }, { - SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME, - BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_NONE, - monitor_subsys_thread_init, - monitor_subsys_thread_update, - NULL, /* create */ - NULL /* modify */ - }, { - SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME, - BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_NONE, - NULL, /* init */ - NULL, /* update */ - NULL, /* create */ - NULL /* modify */ - }, { - SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME, - BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_NONE, - NULL, /* init */ - NULL, /* update */ - NULL, /* create */ - NULL /* modify */ - }, { - SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME, + SLAPD_MONITOR_CONN_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_VOLATILE_CH, monitor_subsys_conn_init, @@ -97,15 +57,23 @@ struct monitorsubsys monitor_subsys[] = { monitor_subsys_conn_create, NULL /* modify */ }, { - SLAPD_MONITOR_RWW, SLAPD_MONITOR_RWW_NAME, + SLAPD_MONITOR_DATABASE_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_PERSISTENT_CH, - monitor_subsys_rww_init, - monitor_subsys_rww_update, - NULL, /* create */ + monitor_subsys_database_init, + NULL, /* update */ + NULL, /* create */ + monitor_subsys_database_modify + }, { + SLAPD_MONITOR_LISTENER_NAME, + BER_BVNULL, BER_BVNULL, BER_BVNULL, + MONITOR_F_PERSISTENT_CH, + monitor_subsys_listener_init, + NULL, /* update */ + NULL, /* create */ NULL /* modify */ }, { - SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME, + SLAPD_MONITOR_LOG_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_NONE, monitor_subsys_log_init, @@ -113,7 +81,7 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* create */ monitor_subsys_log_modify }, { - SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME, + SLAPD_MONITOR_OPS_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_PERSISTENT_CH, monitor_subsys_ops_init, @@ -121,7 +89,23 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* create */ NULL, /* modify */ }, { - SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME, + SLAPD_MONITOR_OVERLAY_NAME, + BER_BVNULL, BER_BVNULL, BER_BVNULL, + MONITOR_F_PERSISTENT_CH, + monitor_subsys_overlay_init, + NULL, /* update */ + NULL, /* create */ + NULL, /* modify */ + }, { + SLAPD_MONITOR_SASL_NAME, + BER_BVNULL, BER_BVNULL, BER_BVNULL, + MONITOR_F_NONE, + NULL, /* init */ + NULL, /* update */ + NULL, /* create */ + NULL /* modify */ + }, { + SLAPD_MONITOR_SENT_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_PERSISTENT_CH, monitor_subsys_sent_init, @@ -129,7 +113,15 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* create */ NULL, /* modify */ }, { - SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME, + SLAPD_MONITOR_THREAD_NAME, + BER_BVNULL, BER_BVNULL, BER_BVNULL, + MONITOR_F_PERSISTENT_CH, + monitor_subsys_thread_init, + monitor_subsys_thread_update, + NULL, /* create */ + NULL /* modify */ + }, { + SLAPD_MONITOR_TIME_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, MONITOR_F_PERSISTENT_CH, monitor_subsys_time_init, @@ -137,14 +129,22 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* create */ NULL, /* modify */ }, { - SLAPD_MONITOR_OVERLAY, SLAPD_MONITOR_OVERLAY_NAME, + SLAPD_MONITOR_TLS_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, - MONITOR_F_PERSISTENT_CH, - monitor_subsys_overlay_init, - NULL, /* update */ + MONITOR_F_NONE, + NULL, /* init */ + NULL, /* update */ NULL, /* create */ - NULL, /* modify */ - }, { -1, NULL } + NULL /* modify */ + }, { + SLAPD_MONITOR_RWW_NAME, + BER_BVNULL, BER_BVNULL, BER_BVNULL, + MONITOR_F_PERSISTENT_CH, + monitor_subsys_rww_init, + monitor_subsys_rww_update, + NULL, /* create */ + NULL /* modify */ + }, { NULL } }; #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC @@ -515,14 +515,14 @@ monitor_back_db_init( &err, LDAP_SCHEMA_ALLOW_ALL ); if ( !at ) { Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: " - "in AttributeType '%s' %s before %s\n", + "in AttributeType \"%s\" %s before %s\n", mat[i].name, ldap_scherr2str(code), err ); return -1; } if ( at->at_oid == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: " - "null OID for attributeType '%s'\n", + "null OID for attributeType \"%s\"\n", mat[i].name, 0, 0 ); return -1; } @@ -530,7 +530,7 @@ monitor_back_db_init( code = at_add(at, &err); if ( code ) { Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: " - "%s in attributeType '%s'\n", + "%s in attributeType \"%s\"\n", scherr2str(code), mat[i].name, 0 ); return -1; } @@ -557,7 +557,7 @@ monitor_back_db_init( LDAP_SCHEMA_ALLOW_ALL ); if ( !oc ) { Debug( LDAP_DEBUG_ANY, - "unable to parse monitor objectclass '%s': " + "unable to parse monitor objectclass \"%s\": " "%s before %s\n" , moc[i].name, ldap_scherr2str(code), err ); return -1; @@ -565,7 +565,7 @@ monitor_back_db_init( if ( oc->oc_oid == NULL ) { Debug( LDAP_DEBUG_ANY, - "objectclass '%s' has no OID\n" , + "objectclass \"%s\" has no OID\n" , moc[i].name, 0, 0 ); return -1; } @@ -573,7 +573,7 @@ monitor_back_db_init( code = oc_add(oc, 0, &err); if ( code ) { Debug( LDAP_DEBUG_ANY, - "objectclass '%s': %s \"%s\"\n" , + "objectclass \"%s\": %s \"%s\"\n" , moc[i].name, scherr2str(code), err ); return -1; } @@ -603,7 +603,7 @@ monitor_back_db_open( { struct monitorinfo *mi = (struct monitorinfo *)be->be_private; struct monitorsubsys *ms; - Entry *e, *e_tmp; + Entry *e, **ep; struct monitorentrypriv *mp; int i; char buf[ BACKMONITOR_BUFSIZE ], *end_of_line; @@ -648,10 +648,90 @@ monitor_back_db_open( mi->mi_creatorsName = be->be_rootdn; } + /* + * creates the "cn=Monitor" entry + */ + snprintf( buf, sizeof( buf ), + "dn: %s\n" + "objectClass: %s\n" + "structuralObjectClass: %s\n" + "cn: Monitor\n" + "%s: This subtree contains monitoring/managing objects.\n" + "%s: This object contains information about this server.\n" +#if 0 + "%s: createTimestamp reflects the time this server instance was created.\n" + "%s: modifyTimestamp reflects the time this server instance was last accessed.\n" +#endif + "creatorsName: %s\n" + "modifiersName: %s\n" + "createTimestamp: %s\n" + "modifyTimestamp: %s\n", + SLAPD_MONITOR_DN, + mi->mi_oc_monitorServer->soc_cname.bv_val, + mi->mi_oc_monitorServer->soc_cname.bv_val, + mi->mi_ad_description->ad_cname.bv_val, + mi->mi_ad_description->ad_cname.bv_val, +#if 0 + mi->mi_ad_description->ad_cname.bv_val, + mi->mi_ad_description->ad_cname.bv_val, +#endif + mi->mi_creatorsName.bv_val, + mi->mi_creatorsName.bv_val, + mi->mi_startTime.bv_val, + mi->mi_startTime.bv_val ); + + e = str2entry( buf ); + if ( e == NULL) { + Debug( LDAP_DEBUG_ANY, + "unable to create \"%s\" entry\n", + SLAPD_MONITOR_DN, 0, 0 ); + return( -1 ); + } + + bv.bv_val = (char *) Versionstr; + end_of_line = strchr( Versionstr, '\n' ); + if ( end_of_line ) { + bv.bv_len = end_of_line - Versionstr; + } else { + bv.bv_len = strlen( Versionstr ); + } + + if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, + &bv, NULL ) ) { + Debug( LDAP_DEBUG_ANY, + "unable to add monitoredInfo to \"%s\" entry\n", + SLAPD_MONITOR_DN, 0, 0 ); + return( -1 ); + } + + if ( mi->mi_l.bv_len ) { + if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) { + Debug( LDAP_DEBUG_ANY, + "unable to add locality to \"%s\" entry\n", + SLAPD_MONITOR_DN, 0, 0 ); + return( -1 ); + } + } + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + + mp->mp_info = NULL; + mp->mp_children = NULL; + mp->mp_next = NULL; + + ep = &mp->mp_children; + + if ( monitor_cache_add( mi, e ) ) { + Debug( LDAP_DEBUG_ANY, + "unable to add entry \"%s\" to cache\n", + SLAPD_MONITOR_DN, 0, 0 ); + return -1; + } + /* * Create all the subsystem specific entries */ - e_tmp = NULL; for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) { int len = strlen( monitor_subsys[ i ].mss_name ); struct berval dn; @@ -706,111 +786,33 @@ monitor_back_db_open( if ( e == NULL) { Debug( LDAP_DEBUG_ANY, - "unable to create '%s' entry\n", + "unable to create \"%s\" entry\n", monitor_subsys[ i ].mss_dn.bv_val, 0, 0 ); return( -1 ); } mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; + mp->mp_next = NULL; mp->mp_info = &monitor_subsys[ i ]; mp->mp_children = NULL; - mp->mp_next = e_tmp; mp->mp_flags = monitor_subsys[ i ].mss_flags; if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, - "unable to add entry '%s' to cache\n", + "unable to add entry \"%s\" to cache\n", monitor_subsys[ i ].mss_dn.bv_val, 0, 0 ); return -1; } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - /* - * creates the "cn=Monitor" entry - */ - snprintf( buf, sizeof( buf ), - "dn: %s\n" - "objectClass: %s\n" - "structuralObjectClass: %s\n" - "cn: Monitor\n" - "%s: This subtree contains monitoring/managing objects.\n" - "%s: This object contains information about this server.\n" -#if 0 - "%s: createTimestamp reflects the time this server instance was created.\n" - "%s: modifyTimestamp reflects the time this server instance was last accessed.\n" -#endif - "creatorsName: %s\n" - "modifiersName: %s\n" - "createTimestamp: %s\n" - "modifyTimestamp: %s\n", - SLAPD_MONITOR_DN, - mi->mi_oc_monitorServer->soc_cname.bv_val, - mi->mi_oc_monitorServer->soc_cname.bv_val, - mi->mi_ad_description->ad_cname.bv_val, - mi->mi_ad_description->ad_cname.bv_val, -#if 0 - mi->mi_ad_description->ad_cname.bv_val, - mi->mi_ad_description->ad_cname.bv_val, -#endif - mi->mi_creatorsName.bv_val, - mi->mi_creatorsName.bv_val, - mi->mi_startTime.bv_val, - mi->mi_startTime.bv_val ); - - e = str2entry( buf ); - if ( e == NULL) { - Debug( LDAP_DEBUG_ANY, - "unable to create '%s' entry\n", - SLAPD_MONITOR_DN, 0, 0 ); - return( -1 ); - } - - bv.bv_val = (char *) Versionstr; - end_of_line = strchr( Versionstr, '\n' ); - if ( end_of_line ) { - bv.bv_len = end_of_line - Versionstr; - } else { - bv.bv_len = strlen( Versionstr ); - } - - if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, - &bv, NULL ) ) { - Debug( LDAP_DEBUG_ANY, - "unable to add monitoredInfo to '%s' entry\n", - SLAPD_MONITOR_DN, 0, 0 ); - return( -1 ); - } - - if ( mi->mi_l.bv_len ) { - if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) { - Debug( LDAP_DEBUG_ANY, - "unable to add locality to '%s' entry\n", - SLAPD_MONITOR_DN, 0, 0 ); - return( -1 ); - } - } - - mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); - e->e_private = ( void * )mp; - - mp->mp_info = NULL; - mp->mp_children = e_tmp; - mp->mp_next = NULL; - - if ( monitor_cache_add( mi, e ) ) { - Debug( LDAP_DEBUG_ANY, - "unable to add entry '%s' to cache\n", - SLAPD_MONITOR_DN, 0, 0 ); - return -1; - } + assert( be ); be->be_private = mi; - assert( be ); - /* * opens the monitor backend */ diff --git a/servers/slapd/back-monitor/listener.c b/servers/slapd/back-monitor/listener.c index bb241020bd..c9b3d4197b 100644 --- a/servers/slapd/back-monitor/listener.c +++ b/servers/slapd/back-monitor/listener.c @@ -32,7 +32,7 @@ monitor_subsys_listener_init( ) { struct monitorinfo *mi; - Entry *e, *e_listener, *e_tmp; + Entry *e_listener, **ep; int i; struct monitorentrypriv *mp; Listener **l; @@ -54,19 +54,22 @@ monitor_subsys_listener_init( if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, - &e_listener ) ) { + &e_listener ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; - for ( i = 0; l[i]; i++ ); - for ( ; i--; ) { + mp = ( struct monitorentrypriv * )e_listener->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + + for ( i = 0; l[i]; i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; + Entry *e; snprintf( buf, sizeof( buf ), "dn: cn=Listener %d,%s\n" @@ -96,10 +99,8 @@ monitor_subsys_listener_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to create entry 'cn=Listener %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - "" ); + "unable to create entry \"cn=Listener %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 ); return( -1 ); } @@ -118,9 +119,7 @@ monitor_subsys_listener_init( if ( l[i]->sl_is_udp ) { struct berval bv; - bv.bv_val = "UDP"; - bv.bv_len = sizeof("UDP")-1; - + BER_BVSTR( &bv, "UDP" ); attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); } @@ -128,7 +127,7 @@ monitor_subsys_listener_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags @@ -137,19 +136,15 @@ monitor_subsys_listener_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_listener_init: " - "unable to add entry 'cn=Listener %d,%s'\n", - i, - monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, - 0 ); + "unable to add entry \"cn=Listener %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_listener->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_listener ); return( 0 ); diff --git a/servers/slapd/back-monitor/log.c b/servers/slapd/back-monitor/log.c index 50c1181e2e..9345275d34 100644 --- a/servers/slapd/back-monitor/log.c +++ b/servers/slapd/back-monitor/log.c @@ -90,15 +90,13 @@ monitor_subsys_log_init( &e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_log_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val, 0, 0 ); return( -1 ); } /* initialize the debug level(s) */ for ( i = 0; int_2_level[ i ].i != 0; i++ ) { - if ( mi->mi_ad_managedInfo->ad_type->sat_equality->smr_normalize ) { int rc; diff --git a/servers/slapd/back-monitor/operation.c b/servers/slapd/back-monitor/operation.c index 8bcce7b2e5..a04aab28d0 100644 --- a/servers/slapd/back-monitor/operation.c +++ b/servers/slapd/back-monitor/operation.c @@ -32,17 +32,17 @@ struct monitor_ops_t { struct berval rdn; struct berval nrdn; } monitor_op[] = { - { BER_BVC( "cn=Bind" ), BER_BVC( "cn=bind" ) }, - { BER_BVC( "cn=Unbind" ), BER_BVC( "cn=unbind" ) }, - { BER_BVC( "cn=Add" ), BER_BVC( "cn=add" ) }, - { BER_BVC( "cn=Delete" ), BER_BVC( "cn=delete" ) }, - { BER_BVC( "cn=Modrdn" ), BER_BVC( "cn=modrdn" ) }, - { BER_BVC( "cn=Modify" ), BER_BVC( "cn=modify" ) }, - { BER_BVC( "cn=Compare" ), BER_BVC( "cn=compare" ) }, - { BER_BVC( "cn=Search" ), BER_BVC( "cn=search" ) }, - { BER_BVC( "cn=Abandon" ), BER_BVC( "cn=abandon" ) }, - { BER_BVC( "cn=Extended" ), BER_BVC( "cn=extended" ) }, - { BER_BVNULL, BER_BVNULL } + { BER_BVC( "cn=Bind" ), BER_BVNULL }, + { BER_BVC( "cn=Unbind" ), BER_BVNULL }, + { BER_BVC( "cn=Add" ), BER_BVNULL }, + { BER_BVC( "cn=Delete" ), BER_BVNULL }, + { BER_BVC( "cn=Modrdn" ), BER_BVNULL }, + { BER_BVC( "cn=Modify" ), BER_BVNULL }, + { BER_BVC( "cn=Compare" ), BER_BVNULL }, + { BER_BVC( "cn=Search" ), BER_BVNULL }, + { BER_BVC( "cn=Abandon" ), BER_BVNULL }, + { BER_BVC( "cn=Extended" ), BER_BVNULL }, + { BER_BVNULL, BER_BVNULL } }; int @@ -52,7 +52,7 @@ monitor_subsys_ops_init( { struct monitorinfo *mi; - Entry *e, *e_tmp, *e_op; + Entry *e_op, **ep; struct monitorentrypriv *mp; char buf[ BACKMONITOR_BUFSIZE ]; int i; @@ -63,7 +63,8 @@ monitor_subsys_ops_init( mi = ( struct monitorinfo * )be->be_private; if ( monitor_cache_get( mi, - &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) { + &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_ops_init: " "unable to get entry \"%s\"\n", @@ -75,9 +76,13 @@ monitor_subsys_ops_init( attr_merge_one( e_op, mi->mi_ad_monitorOpInitiated, &bv_zero, NULL ); attr_merge_one( e_op, mi->mi_ad_monitorOpCompleted, &bv_zero, NULL ); - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_op->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; - for ( i = SLAP_OP_LAST; i-- > 0; ) { + for ( i = 0; i < SLAP_OP_LAST; i++ ) { + struct berval rdn; + Entry *e; /* * Initiated ops @@ -115,9 +120,13 @@ monitor_subsys_ops_init( return( -1 ); } + /* steal normalized RDN */ + dnRdn( &e->e_nname, &rdn ); + ber_dupbv( &monitor_op[i].nrdn, &rdn ); + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \ @@ -131,12 +140,10 @@ monitor_subsys_ops_init( monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 ); return( -1 ); } - - e_tmp = e; - } - mp = ( struct monitorentrypriv * )e_op->e_private; - mp->mp_children = e_tmp; + *ep = e; + ep = &mp->mp_next; + } monitor_cache_release( mi, e_op ); @@ -158,7 +165,6 @@ monitor_subsys_ops_update( #else /* ! HAVE_GMP */ unsigned long nInitiated = 0, nCompleted = 0; - char buf[] = "+9223372036854775807L"; #endif /* ! HAVE_GMP */ struct berval rdn; int i; @@ -174,7 +180,7 @@ monitor_subsys_ops_update( #ifdef HAVE_GMP mpz_init( nInitiated ); mpz_init( nCompleted ); -#endif /* ! HAVE_GMP */ +#endif /* HAVE_GMP */ ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); for ( i = 0; i < SLAP_OP_LAST; i++ ) { @@ -213,46 +219,22 @@ monitor_subsys_ops_update( a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated ); assert ( a != NULL ); - free( a->a_vals[ 0 ].bv_val ); + + /* NOTE: no minus sign is allowed in the counters... */ + UI2BV( &a->a_vals[ 0 ], nInitiated ); #ifdef HAVE_GMP - /* NOTE: there should be no minus sign allowed in the counters... */ - a->a_vals[ 0 ].bv_len = mpz_sizeinbase( nInitiated, 10 ); - a->a_vals[ 0 ].bv_val = ber_memalloc( a->a_vals[ 0 ].bv_len + 1 ); - (void)mpz_get_str( a->a_vals[ 0 ].bv_val, 10, nInitiated ); mpz_clear( nInitiated ); - /* NOTE: according to the documentation, the result - * of mpz_sizeinbase() can exceed the length of the - * string representation of the number by 1 - */ - if ( a->a_vals[ 0 ].bv_val[ a->a_vals[ 0 ].bv_len - 1 ] == '\0' ) { - a->a_vals[ 0 ].bv_len--; - } -#else /* ! HAVE_GMP */ - snprintf( buf, sizeof( buf ), "%ld", nInitiated ); - ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] ); -#endif /* ! HAVE_GMP */ +#endif /* HAVE_GMP */ a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted ); assert ( a != NULL ); - free( a->a_vals[ 0 ].bv_val ); + + /* NOTE: no minus sign is allowed in the counters... */ + UI2BV( &a->a_vals[ 0 ], nCompleted ); #ifdef HAVE_GMP - /* NOTE: there should be no minus sign allowed in the counters... */ - a->a_vals[ 0 ].bv_len = mpz_sizeinbase( nCompleted, 10 ); - a->a_vals[ 0 ].bv_val = ber_memalloc( a->a_vals[ 0 ].bv_len + 1 ); - (void)mpz_get_str( a->a_vals[ 0 ].bv_val, 10, nCompleted ); mpz_clear( nCompleted ); - /* NOTE: according to the documentation, the result - * of mpz_sizeinbase() can exceed the length of the - * string representation of the number by 1 - */ - if ( a->a_vals[ 0 ].bv_val[ a->a_vals[ 0 ].bv_len - 1 ] == '\0' ) { - a->a_vals[ 0 ].bv_len--; - } -#else /* ! HAVE_GMP */ - snprintf( buf, sizeof( buf ), "%ld", nCompleted ); - ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] ); -#endif /* ! HAVE_GMP */ - +#endif /* HAVE_GMP */ + return( 0 ); } diff --git a/servers/slapd/back-monitor/overlay.c b/servers/slapd/back-monitor/overlay.c index 73f9c34d17..8081d77b0c 100644 --- a/servers/slapd/back-monitor/overlay.c +++ b/servers/slapd/back-monitor/overlay.c @@ -36,7 +36,7 @@ monitor_subsys_overlay_init( ) { struct monitorinfo *mi; - Entry *e, *e_overlay, *e_tmp; + Entry *e_overlay, **ep; int i; struct monitorentrypriv *mp; slap_overinst *on; @@ -45,20 +45,24 @@ monitor_subsys_overlay_init( if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn, - &e_overlay ) ) { + &e_overlay ) ) + { Debug( LDAP_DEBUG_ANY, "monitor_subsys_overlay_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_overlay->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; struct berval bv; int j; + Entry *e; snprintf( buf, sizeof( buf ), "dn: cn=Overlay %d,%s\n" @@ -83,10 +87,8 @@ monitor_subsys_overlay_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_overlay_init: " - "unable to create entry 'cn=Overlay %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, - "" ); + "unable to create entry \"cn=Overlay %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, 0 ); return( -1 ); } @@ -130,7 +132,7 @@ monitor_subsys_overlay_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OVERLAY]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_flags @@ -139,19 +141,15 @@ monitor_subsys_overlay_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_overlay_init: " - "unable to add entry 'cn=Overlay %d,%s'\n%s", - i, - monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, - "" ); + "unable to add entry \"cn=Overlay %d,%s\"\n", + i, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_overlay->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_overlay ); return( 0 ); diff --git a/servers/slapd/back-monitor/proto-back-monitor.h b/servers/slapd/back-monitor/proto-back-monitor.h index 072504e59b..cfda44b07b 100644 --- a/servers/slapd/back-monitor/proto-back-monitor.h +++ b/servers/slapd/back-monitor/proto-back-monitor.h @@ -97,6 +97,39 @@ int monitor_subsys_listener_init LDAP_P(( BackendDB *be )); int monitor_subsys_time_init LDAP_P(( BackendDB *be )); int monitor_subsys_time_update LDAP_P(( Operation *op, Entry *e )); +/* NOTE: this macro assumes that bv has been allocated + * by ber_* malloc functions or is { 0L, NULL } */ +#ifdef HAVE_GMP +/* NOTE: according to the documentation, the result + * of mpz_sizeinbase() can exceed the length of the + * string representation of the number by 1 + */ +#define UI2BV(bv,ui) \ + do { \ + ber_len_t len = mpz_sizeinbase( (ui), 10 ); \ + if ( len > (bv)->bv_len ) { \ + (bv)->bv_val = ber_memrealloc( (bv)->bv_val, len + 1 ); \ + } \ + (void)mpz_get_str( (bv)->bv_val, 10, (ui) ); \ + if ( (bv)->bv_val[ len - 1 ] == '\0' ) { \ + len--; \ + } \ + (bv)->bv_len = len; \ + } while ( 0 ) +#else /* ! HAVE_GMP */ +#define UI2BV(bv,ui) \ + do { \ + char buf[] = "+9223372036854775807L"; \ + ber_len_t len; \ + snprintf( buf, sizeof( buf ), "%lu", (ui) ); \ + len = strlen( buf ); \ + if ( len > (bv)->bv_len ) { \ + (bv)->bv_val = ber_memrealloc( (bv)->bv_val, len + 1 ); \ + } \ + AC_MEMCPY( (bv)->bv_val, buf, len + 1 ); \ + } while ( 0 ) +#endif /* ! HAVE_GMP */ + LDAP_END_DECL #endif /* _PROTO_BACK_MONITOR */ diff --git a/servers/slapd/back-monitor/rww.c b/servers/slapd/back-monitor/rww.c index e6818c6bc2..60ad9f468d 100644 --- a/servers/slapd/back-monitor/rww.c +++ b/servers/slapd/back-monitor/rww.c @@ -35,7 +35,7 @@ monitor_subsys_rww_init( { struct monitorinfo *mi; - Entry *e, *e_tmp, *e_conn; + Entry *e, **ep, *e_conn; struct monitorentrypriv *mp; char buf[ BACKMONITOR_BUFSIZE ]; struct berval bv; @@ -48,13 +48,14 @@ monitor_subsys_rww_init( &monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn, &e_conn ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_rww_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_conn->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; /* * Total conns @@ -80,7 +81,7 @@ monitor_subsys_rww_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_rww_init: " - "unable to create entry 'cn=Read,%s'\n", + "unable to create entry \"cn=Read,%s\"\n", monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 ); return( -1 ); } @@ -91,7 +92,7 @@ monitor_subsys_rww_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \ @@ -100,12 +101,13 @@ monitor_subsys_rww_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_rww_init: " - "unable to add entry 'cn=Read,%s'\n", + "unable to add entry \"cn=Read,%s\"\n", monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; /* * Current conns @@ -131,7 +133,7 @@ monitor_subsys_rww_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_rww_init: " - "unable to create entry 'cn=Write,%s'\n", + "unable to create entry \"cn=Write,%s\"\n", monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 ); return( -1 ); } @@ -142,7 +144,7 @@ monitor_subsys_rww_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_RWW]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_RWW].mss_flags \ @@ -151,15 +153,13 @@ monitor_subsys_rww_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_rww_init: " - "unable to add entry 'cn=Write,%s'\n", + "unable to add entry \"cn=Write,%s\"\n", monitor_subsys[SLAPD_MONITOR_RWW].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = e; - - mp = ( struct monitorentrypriv * )e_conn->e_private; - mp->mp_children = e_tmp; + *ep = e; + ep = &mp->mp_next; monitor_cache_release( mi, e_conn ); diff --git a/servers/slapd/back-monitor/search.c b/servers/slapd/back-monitor/search.c index 5a87b10815..fd10c4b182 100644 --- a/servers/slapd/back-monitor/search.c +++ b/servers/slapd/back-monitor/search.c @@ -124,7 +124,7 @@ monitor_back_search( Operation *op, SlapReply *rs ) int rc = LDAP_SUCCESS; Entry *e, *matched = NULL; - Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", ""); + Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 ); /* get entry with reader lock */ diff --git a/servers/slapd/back-monitor/sent.c b/servers/slapd/back-monitor/sent.c index e4cc18d559..f996f9ec55 100644 --- a/servers/slapd/back-monitor/sent.c +++ b/servers/slapd/back-monitor/sent.c @@ -54,7 +54,7 @@ monitor_subsys_sent_init( { struct monitorinfo *mi; - Entry *e_tmp, *e_sent; + Entry **ep, *e_sent; struct monitorentrypriv *mp; int i; @@ -66,15 +66,16 @@ monitor_subsys_sent_init( &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_sent_init: " - "unable to get entry \"%s\"\n%s%s", - monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_sent->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; - for ( i = MONITOR_SENT_LAST; --i >= 0; ) { + for ( i = 0; i < MONITOR_SENT_LAST; i++ ) { char buf[ BACKMONITOR_BUFSIZE ]; struct berval rdn, bv; Entry *e; @@ -117,7 +118,7 @@ monitor_subsys_sent_init( mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \ @@ -126,18 +127,16 @@ monitor_subsys_sent_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_sent_init: " - "unable to add entry \"%s,%s\"\n%s%s", + "unable to add entry \"%s,%s\"\n", monitor_sent[i].rdn.bv_val, monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; } - mp = ( struct monitorentrypriv * )e_sent->e_private; - mp->mp_children = e_tmp; - monitor_cache_release( mi, e_sent ); return( 0 ); @@ -159,9 +158,6 @@ monitor_subsys_sent_update( unsigned long n; #endif /* ! HAVE_GMP */ Attribute *a; -#ifndef HAVE_GMP - char buf[] = "+9223372036854775807L"; -#endif /* ! HAVE_GMP */ int i; assert( mi ); @@ -219,28 +215,13 @@ monitor_subsys_sent_update( ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex); a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter ); - if ( a == NULL ) { - return -1; - } + assert( a ); - free( a->a_vals[ 0 ].bv_val ); + /* NOTE: no minus sign is allowed in the counters... */ + UI2BV( &a->a_vals[ 0 ], n ); #ifdef HAVE_GMP - /* NOTE: there should be no minus sign allowed in the counters... */ - a->a_vals[ 0 ].bv_len = mpz_sizeinbase( n, 10 ); - a->a_vals[ 0 ].bv_val = ber_memalloc( a->a_vals[ 0 ].bv_len + 1 ); - (void)mpz_get_str( a->a_vals[ 0 ].bv_val, 10, n ); mpz_clear( n ); - /* NOTE: according to the documentation, the result - * of mpz_sizeinbase() can exceed the length of the - * string representation of the number by 1 - */ - if ( a->a_vals[ 0 ].bv_val[ a->a_vals[ 0 ].bv_len - 1 ] == '\0' ) { - a->a_vals[ 0 ].bv_len--; - } -#else /* ! HAVE_GMP */ - snprintf( buf, sizeof( buf ), "%lu", n ); - ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] ); -#endif /* ! HAVE_GMP */ +#endif /* HAVE_GMP */ return 0; } diff --git a/servers/slapd/back-monitor/thread.c b/servers/slapd/back-monitor/thread.c index dd5ead33ae..ca96631998 100644 --- a/servers/slapd/back-monitor/thread.c +++ b/servers/slapd/back-monitor/thread.c @@ -36,31 +36,128 @@ monitor_subsys_thread_init( ) { struct monitorinfo *mi; - Entry *e; + struct monitorentrypriv *mp; + Entry *e, **ep, *e_thread; static char buf[ BACKMONITOR_BUFSIZE ]; - struct berval bv; mi = ( struct monitorinfo * )be->be_private; if ( monitor_cache_get( mi, - &monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn, &e ) ) + &monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn, &e_thread ) ) { Debug( LDAP_DEBUG_ANY, - "monitor_subsys_thread_init: unable to get entry '%s'\n", + "monitor_subsys_thread_init: unable to get entry \"%s\"\n", monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - /* initialize the thread number */ - snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max ); + mp = ( struct monitorentrypriv * )e_thread->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; + + /* + * Max + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Max,%s\n" + "objectClass: %s\n" + "structuralObjectClass: %s\n" + "cn: Max\n" + "%s: %d\n" + "creatorsName: %s\n" + "modifiersName: %s\n" + "createTimestamp: %s\n" + "modifyTimestamp: %s\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_dn.bv_val, + mi->mi_oc_monitoredObject->soc_cname.bv_val, + mi->mi_oc_monitoredObject->soc_cname.bv_val, + mi->mi_ad_monitoredInfo->ad_cname.bv_val, + connection_pool_max, + mi->mi_creatorsName.bv_val, + mi->mi_creatorsName.bv_val, + mi->mi_startTime.bv_val, + mi->mi_startTime.bv_val ); + + e = str2entry( buf ); + if ( e == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_thread_init: " + "unable to create entry \"cn=Max,%s\"\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 ); + return( -1 ); + } + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = NULL; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_THREAD]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_THREAD].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_thread_init: " + "unable to add entry \"cn=Max,%s\"\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 ); + return( -1 ); + } + + *ep = e; + ep = &mp->mp_next; + + /* + * Backload + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Backload,%s\n" + "objectClass: %s\n" + "structuralObjectClass: %s\n" + "cn: Backload\n" + "%s: 0\n" + "creatorsName: %s\n" + "modifiersName: %s\n" + "createTimestamp: %s\n" + "modifyTimestamp: %s\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_dn.bv_val, + mi->mi_oc_monitoredObject->soc_cname.bv_val, + mi->mi_oc_monitoredObject->soc_cname.bv_val, + mi->mi_ad_monitoredInfo->ad_cname.bv_val, + mi->mi_creatorsName.bv_val, + mi->mi_creatorsName.bv_val, + mi->mi_startTime.bv_val, + mi->mi_startTime.bv_val ); + + e = str2entry( buf ); + if ( e == NULL ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_thread_init: " + "unable to create entry \"cn=Backload,%s\"\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 ); + return( -1 ); + } - bv.bv_val = buf; - bv.bv_len = strlen( bv.bv_val ); + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = NULL; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_THREAD]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_THREAD].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; - attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); + if ( monitor_cache_add( mi, e ) ) { + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_thread_init: " + "unable to add entry \"cn=Backload,%s\"\n", + monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 ); + return( -1 ); + } + + *ep = e; + ep = &mp->mp_next; - monitor_cache_release( mi, e ); + monitor_cache_release( mi, e_thread ); return( 0 ); } @@ -71,36 +168,34 @@ monitor_subsys_thread_update( Entry *e ) { - struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private; + struct monitorinfo *mi = + (struct monitorinfo *)op->o_bd->be_private; Attribute *a; - struct berval *b = NULL; char buf[ BACKMONITOR_BUFSIZE ]; + static struct berval backload_bv = BER_BVC( "cn=backload" ); + struct berval rdn; + ber_len_t len; assert( mi != NULL ); - snprintf( buf, sizeof( buf ), "backload=%d", - ldap_pvt_thread_pool_backload( &connection_pool ) ); + dnRdn( &e->e_nname, &rdn ); + if ( !dn_match( &rdn, &backload_bv ) ) { + return 0; + } a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo ); - if ( a != NULL ) { - for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) { - if ( strncmp( b[0].bv_val, "backload=", - sizeof( "backload=" ) - 1 ) == 0 ) { - free( b[0].bv_val ); - ber_str2bv( buf, 0, 1, &b[0] ); - break; - } - } + if ( a == NULL ) { + return -1; } - if ( b == NULL || b[0].bv_val == NULL ) { - struct berval bv; - - bv.bv_val = buf; - bv.bv_len = strlen( buf ); - attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, - &bv, NULL ); + snprintf( buf, sizeof( buf ), "%d", + ldap_pvt_thread_pool_backload( &connection_pool ) ); + len = strlen( buf ); + if ( len > a->a_vals[ 0 ].bv_len ) { + a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 ); } + a->a_vals[ 0 ].bv_len = len; + AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 ); return( 0 ); } diff --git a/servers/slapd/back-monitor/time.c b/servers/slapd/back-monitor/time.c index 70ac84d127..2c894dd393 100644 --- a/servers/slapd/back-monitor/time.c +++ b/servers/slapd/back-monitor/time.c @@ -38,7 +38,7 @@ monitor_subsys_time_init( { struct monitorinfo *mi; - Entry *e, *e_tmp, *e_time; + Entry *e, **ep, *e_time; struct monitorentrypriv *mp; char buf[ BACKMONITOR_BUFSIZE ]; @@ -50,13 +50,14 @@ monitor_subsys_time_init( &monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn, &e_time ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_time_init: " - "unable to get entry '%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, - "", "" ); + "unable to get entry \"%s\"\n", + monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = NULL; + mp = ( struct monitorentrypriv * )e_time->e_private; + mp->mp_children = NULL; + ep = &mp->mp_children; snprintf( buf, sizeof( buf ), "dn: cn=Start,%s\n" @@ -82,15 +83,14 @@ monitor_subsys_time_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_time_init: " - "unable to create entry 'cn=Start,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, - "", "" ); + "unable to create entry \"cn=Start,%s\"\n", + monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 ); return( -1 ); } mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \ @@ -99,13 +99,13 @@ monitor_subsys_time_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_time_init: " - "unable to add entry 'cn=Start,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, - "", "" ); + "unable to add entry \"cn=Start,%s\"\n", + monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = e; + *ep = e; + ep = &mp->mp_next; /* * Current @@ -134,15 +134,14 @@ monitor_subsys_time_init( if ( e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_time_init: " - "unable to create entry 'cn=Current,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, - "", "" ); + "unable to create entry \"cn=Current,%s\"\n", + monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 ); return( -1 ); } mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); e->e_private = ( void * )mp; - mp->mp_next = e_tmp; + mp->mp_next = NULL; mp->mp_children = NULL; mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME]; mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \ @@ -151,16 +150,13 @@ monitor_subsys_time_init( if ( monitor_cache_add( mi, e ) ) { Debug( LDAP_DEBUG_ANY, "monitor_subsys_time_init: " - "unable to add entry 'cn=Current,%s'\n%s%s", - monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, - "", "" ); + "unable to add entry \"cn=Current,%s\"\n", + monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 ); return( -1 ); } - e_tmp = e; - - mp = ( struct monitorentrypriv * )e_time->e_private; - mp->mp_children = e_tmp; + *ep = e; + ep = &mp->mp_next; monitor_cache_release( mi, e_time ); @@ -173,13 +169,18 @@ monitor_subsys_time_update( Entry *e ) { - struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private; + struct monitorinfo *mi = + (struct monitorinfo *)op->o_bd->be_private; + + static struct berval bv_current = BER_BVC( "cn=current" ); + struct berval rdn; assert( mi ); assert( e ); + + dnRdn( &e->e_nname, &rdn ); - if ( strncmp( e->e_nname.bv_val, "cn=current", - sizeof("cn=current") - 1 ) == 0 ) { + if ( dn_match( &rdn, &bv_current ) ) { struct tm *tm; #ifdef HAVE_GMTIME_R struct tm tm_buf; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 8ea63ce71f..d01e907d07 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -315,13 +315,12 @@ static Connection* connection_get( ber_socket_t s ) assert( c->c_conn_state != SLAP_C_INVALID ); assert( sd != AC_SOCKET_INVALID ); -#ifdef SLAPD_MONITOR - c->c_activitytime = slap_get_time(); -#else - if( global_idletimeout > 0 ) { +#ifndef SLAPD_MONITOR + if ( global_idletimeout > 0 ) +#endif /* ! SLAPD_MONITOR */ + { c->c_activitytime = slap_get_time(); } -#endif } return c; @@ -514,13 +513,12 @@ long connection_init( /* set to zero until bind, implies LDAP_VERSION3 */ c->c_protocol = 0; -#ifdef SLAPD_MONITOR - c->c_activitytime = c->c_starttime = slap_get_time(); -#else - if( global_idletimeout > 0 ) { +#ifndef SLAPD_MONITOR + if ( global_idletimeout > 0 ) +#endif /* ! SLAPD_MONITOR */ + { c->c_activitytime = c->c_starttime = slap_get_time(); } -#endif #ifdef LDAP_CONNECTIONLESS c->c_is_udp = 0; -- 2.39.5