]> git.sur5r.net Git - openldap/commitdiff
ifdef SLAP_CLEANUP: close db files, free memory, some other cleanup before exit
authorHallvard Furuseth <hallvard@openldap.org>
Tue, 6 Apr 1999 01:55:11 +0000 (01:55 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Tue, 6 Apr 1999 01:55:11 +0000 (01:55 +0000)
12 files changed:
libraries/libldap_r/rdwr.c
servers/slapd/back-ldbm/attr.c
servers/slapd/back-ldbm/cache.c
servers/slapd/back-ldbm/close.c
servers/slapd/back-ldbm/dbcache.c
servers/slapd/back-ldbm/init.c
servers/slapd/back-ldbm/proto-back-ldbm.h
servers/slapd/main.c
servers/slapd/tools/ldif2id2children-bdb2.c
servers/slapd/tools/ldif2id2children.c
servers/slapd/tools/ldif2id2entry-bdb2.c
servers/slapd/tools/ldif2id2entry.c

index 39fd9f7a9a372e5a8555ed1dadfd99e1015a8013..34b2253cd6ef9be241dc981885632395d3a19a42 100644 (file)
@@ -60,6 +60,9 @@ ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rw )
 
        rw->ltrw_valid = 0;
 
+#ifdef SLAP_CLEANUP
+       ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
+#endif
        ldap_pvt_thread_mutex_destroy( &rw->ltrw_mutex );
        ldap_pvt_thread_cond_destroy( &rw->ltrw_read );
        ldap_pvt_thread_cond_destroy( &rw->ltrw_write );
index 07bbcfdb6e2d9fed11b26db2ae079482635235df..a5ece146fbea8640925cc54426965fdd66a82415 100644 (file)
@@ -166,3 +166,22 @@ attr_index_config(
        if ( argc > 1 )
                charray_free( indexes );
 }
+
+
+#ifdef SLAP_CLEANUP
+
+static void
+ainfo_free( void *attr )
+{
+       struct attrinfo *ai = attr;
+       free( ai->ai_type );
+       free( ai );
+}
+
+void
+attr_index_destroy( Avlnode *tree )
+{
+       avl_free( tree, ainfo_free );
+}
+
+#endif /* SLAP_CLEANUP */
index 5386735fcc12d0f8eb86ee089b1be3a636393122..bbb9dd15ebfa8fa2376c78a46e40220f69e43e1f 100644 (file)
@@ -640,6 +640,39 @@ cache_delete_entry_internal(
        return( 0 );
 }
 
+#ifdef SLAP_CLEANUP
+
+void
+cache_release_all( struct cache *cache )
+{
+       Entry *e;
+       int rc;
+
+       /* set cache mutex */
+       ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
+       Debug( LDAP_DEBUG_TRACE, "====> cache_release_all\n", 0, 0, 0 );
+
+       while ( (e = cache->c_lrutail) != NULL && LEI(e)->lei_refcnt == 0 ) {
+#ifdef LDAP_DEBUG
+               assert(!ldap_pvt_thread_rdwr_active(&LEI(e)->lei_rdwr));
+#endif
+               /* delete from cache and lru q */
+               /* XXX do we need rc ? */
+               rc = cache_delete_entry_internal( cache, e );
+               cache_entry_private_destroy( e );
+               entry_free( e );
+       }
+
+       if ( cache->c_cursize )
+               Debug( LDAP_DEBUG_TRACE, "Entry-cache could not be emptied\n", 0, 0, 0 );
+
+       /* free cache mutex */
+       ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+}
+
+#endif /* SLAP_CLEANUP */
+
 #ifdef LDAP_DEBUG
 
 static void
index 5cb9a75b1cc99710160b8a6017812bba5c0b0543..9e520485d7239d40dd572fe5be1a073552e6d8b5 100644 (file)
@@ -21,5 +21,9 @@ ldbm_back_db_close( Backend *be )
        ldbm_cache_flush_all( be );
        Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 );
 
+#ifdef SLAP_CLEANUP
+       cache_release_all( &((struct ldbminfo *) be->be_private)->li_cache );
+#endif
+
        return 0;
 }
index 58b7b8571d34c54ed4889bfb168e22f673dd455e..b068612fe3d57359ef68cc90c6836dee78409eae 100644 (file)
@@ -163,6 +163,22 @@ ldbm_cache_flush_all( Backend *be )
                        Debug( LDAP_DEBUG_TRACE, "ldbm flushing db (%s)\n",
                            li->li_dbcache[i].dbc_name, 0, 0 );
                        ldbm_sync( li->li_dbcache[i].dbc_db );
+#ifdef SLAP_CLEANUP
+                       if ( li->li_dbcache[i].dbc_refcnt != 0 ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                      "refcnt = %d, couldn't close db (%s)\n",
+                                      li->li_dbcache[i].dbc_refcnt,
+                                      li->li_dbcache[i].dbc_name, 0 );
+                       } else {
+                               Debug( LDAP_DEBUG_TRACE,
+                                      "ldbm closing db (%s)\n",
+                                      li->li_dbcache[i].dbc_name, 0, 0 );
+                               ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
+                               ldbm_close( li->li_dbcache[i].dbc_db );
+                               free( li->li_dbcache[i].dbc_name );
+                               li->li_dbcache[i].dbc_name = NULL;
+                       }
+#endif /* SLAP_CLEANUP */
                }
        }
        ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
index b3c2845fa9ca63cb7319554137fcf2fd5e6106b1..4ca59cf035004a1cc541cd6e935627dc3c93a28d 100644 (file)
@@ -157,6 +157,19 @@ ldbm_back_db_destroy(
 )
 {
        /* should free/destroy every in be_private */
+#ifdef SLAP_CLEANUP
+       struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+       free( li->li_nextid_file );
+       free( li->li_directory );
+       attr_index_destroy( li->li_attrs );
+
+       ldap_pvt_thread_mutex_destroy( &li->li_root_mutex );
+       ldap_pvt_thread_mutex_destroy( &li->li_add_mutex );
+       ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
+       ldap_pvt_thread_mutex_destroy( &li->li_nextid_mutex );
+       ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
+       ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
+#endif /* SLAP_CLEANUP */
        free( be->be_private );
        be->be_private = NULL;
        return 0;
index 61fc54074d83c7e5853e79e356d50a8526238109..e64c6a4065219297951611d08660828291af17d0 100644 (file)
@@ -29,6 +29,9 @@ void attr_masks LDAP_P(( struct ldbminfo *li, char *type, int *indexmask,
  int *syntaxmask ));
 void attr_index_config LDAP_P(( struct ldbminfo *li, char *fname, int lineno,
  int argc, char **argv, int init ));
+#ifdef SLAP_CLEANUP
+void attr_index_destroy LDAP_P(( Avlnode *tree ));
+#endif
 
 /*
  * cache.c
@@ -43,6 +46,9 @@ void cache_return_entry_rw LDAP_P(( struct cache *cache, Entry *e, int rw ));
 ID cache_find_entry_dn2id LDAP_P(( Backend *be, struct cache *cache, char *dn ));
 Entry * cache_find_entry_id LDAP_P(( struct cache *cache, ID id, int rw ));
 int cache_delete_entry LDAP_P(( struct cache *cache, Entry *e ));
+#ifdef SLAP_CLEANUP
+void cache_release_all LDAP_P(( struct cache *cache ));
+#endif
 
 /*
  * dbcache.c
index a3cbae3b2d26b175c8655149b8d96d6d58684e2c..4eee5962d007077c9b962802519bc22228cf3920 100644 (file)
@@ -321,6 +321,10 @@ destroy:
 
        Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
 
+#ifdef SLAP_CLEANUP
+       closelog();
+#endif
+
        return rc;
 }
 
index 1d3e01be2029052ed2a5a53b4a42fd66de50e394..5b850544610bdec2866be058676ecebe5a7f1bd1 100644 (file)
@@ -301,6 +301,11 @@ main( int argc, char **argv )
                }
        }
 
+#ifdef SLAP_CLEANUP
+       bdb2i_cache_close( be, db2 );
+       bdb2i_cache_close( be, db );
+#endif
+
        slap_shutdown(dbnum);
        slap_destroy();
 
index 16418a8d34f8fe8f74c8dc1940413994aa0400ba..4225786c630c6573e0512557138d5c446ad0634b 100644 (file)
@@ -301,6 +301,11 @@ main( int argc, char **argv )
                }
        }
 
+#ifdef SLAP_CLEANUP
+       ldbm_cache_close( be, db2 );
+       ldbm_cache_close( be, db );
+#endif
+
        slap_shutdown(dbnum);
        slap_destroy();
 
index b46cf26e8b57905018f046bd8a3a418253b5d293..b3769b3d4e7b54223996137b03e64a744106bc2d 100644 (file)
@@ -185,6 +185,10 @@ main( int argc, char **argv )
        id++;
        bdb2i_put_nextid( be, id );
 
+#ifdef SLAP_CLEANUP
+       bdb2i_cache_close( be, db );
+#endif
+
        slap_shutdown(dbnum);
 
        slap_destroy();
index 7dbf064f472e4ab334c4f4ec6eef2b8405c1dba8..6e97fbe55ced898f05955df7be54a3c84b0eccef 100644 (file)
@@ -182,6 +182,10 @@ main( int argc, char **argv )
                }
        }
 
+#ifdef SLAP_CLEANUP
+       ldbm_cache_close( be, db );
+#endif
+
        slap_shutdown(dbnum);
 
        id++;