]> git.sur5r.net Git - openldap/commitdiff
cleanup monitoring resources
authorPierangelo Masarati <ando@openldap.org>
Wed, 6 Sep 2006 12:07:03 +0000 (12:07 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 6 Sep 2006 12:07:03 +0000 (12:07 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/monitor.c

index c6788417e9a3a1a34b76d083fabd12eb6d662244..9173e6a13ccd74d7024b7058ef4906751666c8e1 100644 (file)
@@ -150,6 +150,13 @@ struct bdb_db_info {
        DB                      *bdi_db;
 };
 
+typedef struct bdb_monitor_cleanup_t {
+       void            *bdm_cb;
+       struct berval   bdm_base;
+       int             bdm_scope;
+       struct berval   bdm_filter;
+} bdb_monitor_cleanup_t;
+
 /* From ldap_rq.h */
 struct re_s;
 
@@ -206,6 +213,7 @@ struct bdb_info {
        int             bi_modrdns;             /* number of modrdns completed */
        ldap_pvt_thread_mutex_t bi_modrdns_mutex;
 #endif
+       bdb_monitor_cleanup_t   bi_monitor_cleanup;
 };
 
 #define bi_id2entry    bi_databases[BDB_ID2ENTRY]
index fcdab9ad2c5108d75be5218d48f7dbbf19d43abd..a5601bf556f815e6cffce88daf6ee0a3c0ae39d6 100644 (file)
@@ -447,6 +447,9 @@ bdb_db_close( BackendDB *be )
        struct bdb_db_info *db;
        bdb_idl_cache_entry_t *entry, *next_entry;
 
+       /* monitor setup */
+       (void)bdb_monitor_close( be );
+
        bdb->bi_flags &= ~BDB_IS_OPEN;
 
        ber_bvarray_free( bdb->bi_db_config );
index abaf94c66dd364b0ccff5c06124eadb03bbf81fc..5cd3bc22c0ced25dee85093b102064d65799d4a8 100644 (file)
@@ -318,11 +318,16 @@ bdb_monitor_open( BackendDB *be )
        struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
        Attribute               *a, *next;
        monitor_callback_t      *cb;
-       struct berval           base = BER_BVC( "cn=databases,cn=monitor" );
-       struct berval           suffix, filter;
+       struct berval           suffix, *filter, *base;
        char                    *ptr;
        int                     rc = 0;
 
+       bdb->bi_monitor_cleanup.bdm_scope = LDAP_SCOPE_ONELEVEL;
+       base = &bdb->bi_monitor_cleanup.bdm_base;
+       BER_BVSTR( base, "cn=databases,cn=monitor" );
+       filter = &bdb->bi_monitor_cleanup.bdm_filter;
+       BER_BVZERO( filter );
+
        /* don't bother if monitor is not configured */
        if ( !monitor_back_is_configured() ) {
                static int warning = 0;
@@ -349,14 +354,14 @@ bdb_monitor_open( BackendDB *be )
                ldap_bv2escaped_filter_value( &be->be_nsuffix[ 0 ], &suffix );
        }
        
-       filter.bv_len = STRLENOF( "(namingContexts:distinguishedNameMatch:=)" ) + suffix.bv_len;
-       ptr = filter.bv_val = ch_malloc( filter.bv_len + 1 );
+       filter->bv_len = STRLENOF( "(namingContexts:distinguishedNameMatch:=)" ) + suffix.bv_len;
+       ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
        ptr = lutil_strcopy( ptr, "(namingContexts:distinguishedNameMatch:=" );
        ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
        ptr[ 0 ] = ')';
        ptr++;
        ptr[ 0 ] = '\0';
-       assert( filter.bv_len == ptr - filter.bv_val );
+       assert( filter->bv_len == ptr - filter->bv_val );
        
        if ( suffix.bv_val != be->be_nsuffix[ 0 ].bv_val ) {
                ch_free( suffix.bv_val );
@@ -449,24 +454,36 @@ bdb_monitor_open( BackendDB *be )
        cb->mc_free = bdb_monitor_free;
        cb->mc_private = (void *)bdb;
 
-       rc = monitor_back_register_entry_attrs( NULL,
-               a, cb, &base, LDAP_SCOPE_ONELEVEL, &filter );
+       rc = monitor_back_register_entry_attrs( NULL, a, cb,
+               base, LDAP_SCOPE_ONELEVEL, filter );
 
 cleanup:;
        if ( rc != 0 ) {
                if ( cb != NULL ) {
                        ch_free( cb );
+                       cb = NULL;
+               }
+
+               if ( a != NULL ) {
+                       attrs_free( a );
+                       a = NULL;
                }
-       }
 
-       if ( !BER_BVISNULL( &filter ) ) {
-               ch_free( filter.bv_val );
+               if ( !BER_BVISNULL( filter ) ) {
+                       ch_free( filter->bv_val );
+                       BER_BVZERO( filter );
+               }
        }
 
+       /* store for cleanup */
+       bdb->bi_monitor_cleanup.bdm_cb = (void *)cb;
+
+       /* we don't need to keep track of the attributes, because
+        * bdb_monitor_free() takes care of everything */
        if ( a != NULL ) {
                attrs_free( a );
        }
-       
+
        return rc;
 }
 
@@ -476,6 +493,22 @@ cleanup:;
 int
 bdb_monitor_close( BackendDB *be )
 {
+       struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
+
+       if ( !BER_BVISNULL( &bdb->bi_monitor_cleanup.bdm_filter ) ) {
+               monitor_back_unregister_entry_callback( NULL,
+                       (monitor_callback_t *)bdb->bi_monitor_cleanup.bdm_cb,
+                       &bdb->bi_monitor_cleanup.bdm_base,
+                       bdb->bi_monitor_cleanup.bdm_scope,
+                       &bdb->bi_monitor_cleanup.bdm_filter );
+
+               if ( !BER_BVISNULL( &bdb->bi_monitor_cleanup.bdm_filter ) ) {
+                       ch_free( bdb->bi_monitor_cleanup.bdm_filter.bv_val );
+               }
+
+               memset( &bdb->bi_monitor_cleanup, 0, sizeof( bdb->bi_monitor_cleanup ) );
+       }
+
        return 0;
 }