]> git.sur5r.net Git - openldap/commitdiff
don't add databases twice; but try as hard as possible...
authorPierangelo Masarati <ando@openldap.org>
Wed, 21 Mar 2007 23:22:49 +0000 (23:22 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 21 Mar 2007 23:22:49 +0000 (23:22 +0000)
servers/slapd/back-bdb/monitor.c
servers/slapd/back-monitor/database.c
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/proto-back-monitor.h

index 603a4ea03bf1ff82c62d390debd0f593c6f84b6c..87d31207d421d4179a2bdf7937c8073fb40700e6 100644 (file)
@@ -455,10 +455,12 @@ bdb_monitor_db_open( BackendDB *be )
        cb->mc_free = bdb_monitor_free;
        cb->mc_private = (void *)bdb;
 
-       (void)mbe->register_database( be );
-
-       rc = mbe->register_entry_attrs( NULL, a, cb,
-               base, bdb->bi_monitor.bdm_scope, filter );
+       /* make sure the database is registered; then add monitor attributes */
+       rc = mbe->register_database( be );
+       if ( rc == 0 ) {
+               rc = mbe->register_entry_attrs( NULL, a, cb,
+                       base, bdb->bi_monitor.bdm_scope, filter );
+       }
 
 cleanup:;
        if ( rc != 0 ) {
index 2837113787f0deaa8e181ca42fbbe88e878a1ab9..2b7d678eed0d20284c5ccab12c233f43ca01c8e9 100644 (file)
@@ -353,9 +353,14 @@ monitor_back_register_database(
                                *ms_database,
                                *ms_overlay;
        struct berval           bv;
+       char                    buf[ BACKMONITOR_BUFSIZE ];
 
        assert( be_monitor != NULL );
 
+       if ( !monitor_subsys_is_opened() ) {
+               return monitor_back_register_database_limbo( be );
+       }
+
        mi = ( monitor_info_t * )be_monitor->be_private;
 
        ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
@@ -401,31 +406,45 @@ monitor_back_register_database(
 
        mp = ( monitor_entry_t * )e_database->e_private;
        for ( i = -1, ep = &mp->mp_children; *ep; i++ ) {
+               Attribute       *a;
+
+               a = attr_find( (*ep)->e_attrs, slap_schema.si_ad_namingContexts );
+               if ( a ) {
+                       int             j, k;
+
+                       for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
+                               for ( k = 0; !BER_BVISNULL( &be->be_nsuffix[ k ] ); k++ ) {
+                                       if ( dn_match( &a->a_nvals[ j ], &be->be_nsuffix[ k ] ) ) {
+                                               rc = 0;
+                                               goto done;
+                                       }
+                               }
+                       }
+               }
+
                mp = ( monitor_entry_t * )(*ep)->e_private;
 
                assert( mp != NULL );
                ep = &mp->mp_next;
        }
 
-       {       
-               char            buf[ BACKMONITOR_BUFSIZE ];
-
-               bv.bv_val = buf;
-               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", i );
-               if ( bv.bv_len >= sizeof( buf ) ) {
-                       return -1;
-               }
-               
-               rc = monitor_subsys_database_init_one( mi, be,
-                       ms_database, ms_backend, ms_overlay, &bv, e_database, &ep );
-               if ( rc != 0 ) {
-                       return rc;
-               }
+       bv.bv_val = buf;
+       bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", i );
+       if ( bv.bv_len >= sizeof( buf ) ) {
+               rc = -1;
+               goto done;
        }
        
+       rc = monitor_subsys_database_init_one( mi, be,
+               ms_database, ms_backend, ms_overlay, &bv, e_database, &ep );
+       if ( rc != 0 ) {
+               goto done;
+       }
+
+done:;
        monitor_cache_release( mi, e_database );
 
-       return 0;
+       return rc;
 }
 
 int
index 780e2f5a7ce0ce7c017952c69df6c8a98b2aef72..f2b798b1561f272ac54dcf7e8d9a0bb45b8c2602 100644 (file)
@@ -225,6 +225,12 @@ static struct monitor_subsys_t known_monitor_subsys[] = {
                }, { NULL }
 };
 
+int
+monitor_subsys_is_opened( void )
+{
+       return monitor_subsys_opened;
+}
+
 int
 monitor_back_register_subsys(
        monitor_subsys_t        *ms )
@@ -249,7 +255,7 @@ monitor_back_register_subsys(
        /* if a subsystem is registered __AFTER__ subsystem 
         * initialization (depending on the sequence the databases
         * are listed in slapd.conf), init it */
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
 
                /* FIXME: this should only be possible
                 * if be_monitor is already initialized */
@@ -269,11 +275,20 @@ enum {
        LIMBO_ENTRY,
        LIMBO_ENTRY_PARENT,
        LIMBO_ATTRS,
-       LIMBO_CB
+       LIMBO_CB,
+       LIMBO_BACKEND,
+       LIMBO_DATABASE,
+       LIMBO_OVERLAY_INFO,
+       LIMBO_OVERLAY,
+
+       LIMBO_LAST
 };
 
 typedef struct entry_limbo_t {
        int                     el_type;
+       BackendInfo             *el_bi;
+       BackendDB               *el_be;
+       slap_overinst           *el_on;
        Entry                   *el_e;
        Attribute               *el_a;
        struct berval           el_ndn;
@@ -313,6 +328,62 @@ monitor_back_register_overlay(
        return -1;
 }
 
+int
+monitor_back_register_backend_limbo(
+       BackendInfo             *bi )
+{
+       return -1;
+}
+
+int
+monitor_back_register_database_limbo(
+       BackendDB               *be )
+{
+       entry_limbo_t   **elpp, el = { 0 };
+       monitor_info_t  *mi;
+
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_database_limbo: "
+                       "monitor database not configured.\n",
+                       0, 0, 0 );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
+
+
+       el.el_type = LIMBO_DATABASE;
+
+       el.el_be = be;
+       
+       for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+                       *elpp;
+                       elpp = &(*elpp)->el_next )
+               /* go to last */;
+
+       *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
+
+       el.el_next = NULL;
+       **elpp = el;
+
+       return 0;
+}
+
+int
+monitor_back_register_overlay_info_limbo(
+       slap_overinst           *on )
+{
+       return -1;
+}
+
+int
+monitor_back_register_overlay_limbo(
+       BackendDB               *be )
+{
+       return -1;
+}
+
 int
 monitor_back_register_entry(
        Entry                   *e,
@@ -336,7 +407,7 @@ monitor_back_register_entry(
        assert( e != NULL );
        assert( e->e_private == NULL );
        
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry           *e_parent = NULL,
                                *e_new = NULL,
                                **ep = NULL;
@@ -515,7 +586,7 @@ monitor_back_register_entry_parent(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry           *e_parent = NULL,
                                *e_new = NULL,
                                **ep = NULL;
@@ -883,7 +954,7 @@ monitor_back_register_entry_attrs(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                Attribute               **atp = NULL;
                monitor_entry_t         *mp = NULL;
@@ -1083,7 +1154,7 @@ monitor_back_unregister_entry(
 
        assert( mi != NULL );
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
                monitor_callback_t      *cb = NULL;
@@ -1196,7 +1267,7 @@ monitor_back_unregister_entry_parent(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
 
@@ -1351,7 +1422,7 @@ monitor_back_unregister_entry_attrs(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
                int                     freeit = 0;
@@ -2296,6 +2367,22 @@ monitor_back_db_open(
                                                &el->el_filter );
                                break;
 
+                       case LIMBO_BACKEND:
+                               rc = monitor_back_register_backend( el->el_bi );
+                               break;
+
+                       case LIMBO_DATABASE:
+                               rc = monitor_back_register_database( el->el_be );
+                               break;
+
+                       case LIMBO_OVERLAY_INFO:
+                               rc = monitor_back_register_overlay_info( el->el_on );
+                               break;
+
+                       case LIMBO_OVERLAY:
+                               rc = monitor_back_register_overlay( el->el_be );
+                               break;
+
                        default:
                                assert( 0 );
                        }
index a0c8d293962fd3a01be38c5fd9345388c6cc935f..f09522db1ff77b7585c08eece0e32014d42a2a06 100644 (file)
@@ -135,6 +135,9 @@ monitor_entry_stub LDAP_P((
  * init
  */
 extern int
+monitor_subsys_is_opened LDAP_P((
+       void ));
+extern int
 monitor_back_register_subsys LDAP_P((
        monitor_subsys_t        *ms ));
 extern int
@@ -149,6 +152,18 @@ monitor_back_register_overlay_info LDAP_P((
 extern int
 monitor_back_register_overlay LDAP_P((
        BackendDB               *be ));
+extern int
+monitor_back_register_backend_limbo LDAP_P((
+       BackendInfo             *bi ));
+extern int
+monitor_back_register_database_limbo LDAP_P((
+       BackendDB               *be ));
+extern int
+monitor_back_register_overlay_info_limbo LDAP_P((
+       slap_overinst           *on ));
+extern int
+monitor_back_register_overlay_limbo LDAP_P((
+       BackendDB               *be ));
 extern monitor_subsys_t *
 monitor_back_get_subsys LDAP_P((
        const char              *name ));