cleanup monitoring resources

This commit is contained in:
Pierangelo Masarati 2006-09-06 12:07:03 +00:00
parent 127ac65c44
commit 1fc5e8e057
3 changed files with 55 additions and 11 deletions

View 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]

View 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 );

View 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,20 +454,32 @@ 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 );
BER_BVZERO( filter );
}
}
if ( !BER_BVISNULL( &filter ) ) {
ch_free( filter.bv_val );
}
/* 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 );
}
@ -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;
}