From: Pierangelo Masarati Date: Wed, 6 Sep 2006 12:07:03 +0000 (+0000) Subject: cleanup monitoring resources X-Git-Tag: OPENLDAP_REL_ENG_2_3_MP~198 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1fc5e8e057f2ea2f4baf4606434f15fbc63ed392;p=openldap cleanup monitoring resources --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index c6788417e9..9173e6a13c 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -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] diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index fcdab9ad2c..a5601bf556 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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 ); diff --git a/servers/slapd/back-bdb/monitor.c b/servers/slapd/back-bdb/monitor.c index abaf94c66d..5cd3bc22c0 100644 --- a/servers/slapd/back-bdb/monitor.c +++ b/servers/slapd/back-bdb/monitor.c @@ -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; }