]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/thread.c
more (in)sanity stuff
[openldap] / servers / slapd / back-monitor / thread.c
index 99c36b760e1a4e5460718dcd22b0fb0ae7c0b499..c76acaa86468941669261ff0e7bd336aa0b81ab4 100644 (file)
 
 #include <ldap_rq.h>
 
+static int 
+monitor_subsys_thread_update( 
+       Operation               *op,
+       SlapReply               *rs,
+       Entry                   *e );
+
 /*
- * initializes log subentry
-*   */
+ * initializes log subentry
+ */
 int
 monitor_subsys_thread_init(
        BackendDB               *be,
@@ -43,6 +49,8 @@ monitor_subsys_thread_init(
        Entry           *e, **ep, *e_thread;
        static char     buf[ BACKMONITOR_BUFSIZE ];
 
+       ms->mss_update = monitor_subsys_thread_update;
+
        mi = ( monitor_info_t * )be->be_private;
 
        if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
@@ -216,11 +224,11 @@ monitor_subsys_thread_init(
        return( 0 );
 }
 
-int 
+static int 
 monitor_subsys_thread_update( 
        Operation               *op,
-       Entry                   *e
-)
+       SlapReply               *rs,
+       Entry                   *e )
 {
        monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
        Attribute               *a;
@@ -229,25 +237,29 @@ monitor_subsys_thread_update(
        static struct berval    runqueue_bv = BER_BVC( "cn=runqueue" );
        struct berval           rdn, bv;
        ber_len_t               len;
-       int which = 0;
+       int which = 0, i;
        struct re_s *re;
 
        assert( mi != NULL );
 
        dnRdn( &e->e_nname, &rdn );
-       if ( dn_match( &rdn, &backload_bv ))
+       if ( dn_match( &rdn, &backload_bv ) ) {
                which = 1;
-       else if ( dn_match( &rdn, &runqueue_bv ))
+
+       } else if ( dn_match( &rdn, &runqueue_bv ) ) {
                which = 2;
-       else
-               return 0;
 
-       switch( which ) {
+       } else {
+               return SLAP_CB_CONTINUE;
+       }
+
+       a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
+       if ( a == NULL ) {
+               return rs->sr_err = LDAP_OTHER;
+       }
+
+       switch ( which ) {
        case 1:
-               a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
-               if ( a == NULL ) {
-                       return -1;
-               }
                snprintf( buf, sizeof( buf ), "%d", 
                        ldap_pvt_thread_pool_backload( &connection_pool ) );
                len = strlen( buf );
@@ -257,14 +269,18 @@ monitor_subsys_thread_update(
                a->a_vals[ 0 ].bv_len = len;
                AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
                break;
+
        case 2:
-               attr_delete( &e->e_attrs, mi->mi_ad_monitoredInfo );
+               for ( i = 0; !BER_BVISNULL( a->a_vals + i ); i++) {
+                       ch_free( a->a_vals[i].bv_val );
+                       BER_BVZERO( a->a_vals + i );
+               }
                bv.bv_val = buf;
                ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) {
                        bv.bv_len = snprintf( buf, sizeof( buf ), "%s(%s)",
                                re->tname, re->tspec );
-                       attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
+                       value_add_one( &a->a_vals, &bv );
                }
                ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                break;
@@ -272,6 +288,6 @@ monitor_subsys_thread_update(
 
        /* FIXME: touch modifyTimestamp? */
 
-       return( 0 );
+       return SLAP_CB_CONTINUE;
 }