From 8eab487020d8808219807acc6f59e25b88ea77d8 Mon Sep 17 00:00:00 2001
From: Pierangelo Masarati <ando@openldap.org>
Date: Sat, 9 Sep 2006 16:24:35 +0000
Subject: [PATCH] further improve monitoring setup and cleanup

---
 servers/slapd/back-bdb/init.c    |  7 +++++--
 servers/slapd/back-bdb/monitor.c | 22 ++++++++++++----------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c
index a5601bf556..7b85509c7b 100644
--- a/servers/slapd/back-bdb/init.c
+++ b/servers/slapd/back-bdb/init.c
@@ -45,6 +45,7 @@ static int
 bdb_db_init( BackendDB *be )
 {
 	struct bdb_info	*bdb;
+	int rc;
 
 	Debug( LDAP_DEBUG_TRACE,
 		LDAP_XSTRING(bdb_db_init) ": Initializing " BDB_UCTYPE " database\n",
@@ -80,7 +81,9 @@ bdb_db_init( BackendDB *be )
 	be->be_private = bdb;
 	be->be_cf_ocs = be->bd_info->bi_cf_ocs;
 
-	return 0;
+	rc = bdb_monitor_init( be );
+
+	return rc;
 }
 
 static int
@@ -447,7 +450,7 @@ bdb_db_close( BackendDB *be )
 	struct bdb_db_info *db;
 	bdb_idl_cache_entry_t *entry, *next_entry;
 
-	/* monitor setup */
+	/* monitor handling */
 	(void)bdb_monitor_close( be );
 
 	bdb->bi_flags &= ~BDB_IS_OPEN;
diff --git a/servers/slapd/back-bdb/monitor.c b/servers/slapd/back-bdb/monitor.c
index 734e6e2b3e..237dfc4d04 100644
--- a/servers/slapd/back-bdb/monitor.c
+++ b/servers/slapd/back-bdb/monitor.c
@@ -330,6 +330,8 @@ done_oc:;
 int
 bdb_monitor_init( BackendDB *be )
 {
+	SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
+
 	return 0;
 }
 
@@ -364,11 +366,7 @@ bdb_monitor_open( BackendDB *be )
 		return 0;
 	}
 
-	/* monitor_back_register_entry_attrs() with a NULL ndn,
-	 * base="cn=Databases,cn=Monitor", scope=LDAP_SCOPE_ONE 
-	 * and filter="(namingContexts:distinguishedNameMatch:=<suffix>)" */
-
-	bdb->bi_monitor.bdm_scope = LDAP_SCOPE_ONELEVEL;
+	bdb->bi_monitor.bdm_scope = LDAP_SCOPE_SUBORDINATE;
 	base = &bdb->bi_monitor.bdm_nbase;
 	BER_BVSTR( base, "cn=databases,cn=monitor" );
 	filter = &bdb->bi_monitor.bdm_filter;
@@ -382,12 +380,16 @@ bdb_monitor_open( BackendDB *be )
 		ldap_bv2escaped_filter_value( &be->be_nsuffix[ 0 ], &suffix );
 	}
 	
-	filter->bv_len = STRLENOF( "(namingContexts:distinguishedNameMatch:=)" ) + suffix.bv_len;
+	filter->bv_len = STRLENOF( "(&(monitoredInfo=" )
+		+ strlen( be->bd_info->bi_type )
+		+ STRLENOF( ")(namingContexts:distinguishedNameMatch:=" )
+		+ suffix.bv_len + STRLENOF( "))" );
 	ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
-	ptr = lutil_strcopy( ptr, "(namingContexts:distinguishedNameMatch:=" );
+	ptr = lutil_strcopy( ptr, "(&(monitoredInfo=" );
+	ptr = lutil_strcopy( ptr, be->bd_info->bi_type );
+	ptr = lutil_strcopy( ptr, ")(namingContexts:distinguishedNameMatch:=" );
 	ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
-	ptr[ 0 ] = ')';
-	ptr++;
+	ptr = lutil_strcopy( ptr, "))" );
 	ptr[ 0 ] = '\0';
 	assert( filter->bv_len == ptr - filter->bv_val );
 	
@@ -483,7 +485,7 @@ bdb_monitor_open( BackendDB *be )
 	cb->mc_private = (void *)bdb;
 
 	rc = monitor_back_register_entry_attrs( NULL, a, cb,
-		base, LDAP_SCOPE_ONELEVEL, filter );
+		base, LDAP_SCOPE_SUBORDINATE, filter );
 
 cleanup:;
 	if ( rc != 0 ) {
-- 
GitLab