]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb2/txn.c
Change 'unsigned long len' to ber_len_t in get_filter()
[openldap] / servers / slapd / back-bdb2 / txn.c
index 7d1ced6b343063697a3c810ad18e1a4e8c1726bc..b2e2b0721f5ef9e0767931e65a68a0c2a2431240 100644 (file)
@@ -1,5 +1,10 @@
 /* txn.c - TP support functions of the bdb2 backend */
 
+#include "portable.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
 #include "txn.h"
 
 
@@ -51,8 +56,9 @@ bdb2i_init_db_file_cache( struct ldbminfo *li, BDB2_TXN_FILES *fileinfo )
 
        fileinfo->dbc_refcnt = 1;
 
-       sprintf( buf, "%s%s%s", li->li_directory, DEFAULT_DIRSEP,
-                                       fileinfo->dbc_name );
+       sprintf( buf, "%s" LDAP_DIRSEP "%s",
+               li->li_directory, fileinfo->dbc_name );
+
        if ( stat( buf, &st ) == 0 ) {
                fileinfo->dbc_blksize = st.st_blksize;
        } else {
@@ -133,11 +139,12 @@ bdb2i_txn_attr_config(
                        if ( open && strcasecmp( fileName, "objectclass" )) {
 
                                /*  re-use filename to get the complete path  */
-                               sprintf( fileName, "%s%s%s",
-                                                       li->li_directory, DEFAULT_DIRSEP, p->dbc_name );
+                               sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+                                                       li->li_directory, p->dbc_name );
 
                                /*  since we have an mpool, we should not define a cache size */
-                               p->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
+                               p->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
+                                                                       LDBM_WRCREAT, li->li_mode, 0 );
 
                                /*  if the files could not be opened, something is wrong;
                                        complain  */
@@ -177,11 +184,10 @@ bdb2i_open_nextid( BackendDB *be )
        BDB2_TXN_HEAD   *head = &li->li_txn_head;
        LDBM            db = NULL;
        DB_INFO                 dbinfo;
-       DB_ENV                  *dbenv = get_dbenv( be );
        char            fileName[MAXPATHLEN];
 
-       sprintf( fileName, "%s%s%s",
-                               li->li_directory, DEFAULT_DIRSEP, NEXTID_NAME );
+       sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+                               li->li_directory, NEXTID_NAME );
 
        /*  try to open the file for read and write  */
        memset( &dbinfo, 0, sizeof( dbinfo ));
@@ -189,7 +195,7 @@ bdb2i_open_nextid( BackendDB *be )
        dbinfo.db_malloc    = ldbm_malloc;
 
        (void) db_open( fileName, DB_RECNO, DB_CREATE | DB_THREAD,
-                                       li->li_mode, dbenv, &dbinfo, &db );
+                                       li->li_mode, &bdb2i_dbEnv, &dbinfo, &db );
 
        if ( db == NULL ) {
 
@@ -224,11 +230,12 @@ bdb2i_txn_open_files( BackendDB *be )
        for ( dbFile = head->dbFiles; dbFile; dbFile = dbFile->next ) {
                char   fileName[MAXPATHLEN];
 
-               sprintf( fileName, "%s%s%s",
-                                       li->li_directory, DEFAULT_DIRSEP, dbFile->dbc_name );
+               sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+                                       li->li_directory, dbFile->dbc_name );
 
                /*  since we have an mpool, we should not define a cache size */
-               dbFile->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
+               dbFile->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
+                                                       LDBM_WRCREAT, li->li_mode, 0 );
 
                /*  if the files could not be opened, something is wrong; complain  */
                if ( dbFile->dbc_db == NULL ) {
@@ -271,7 +278,8 @@ bdb2i_txn_close_files( BackendDB *be )
 
        }
 
-       ldbm_close( head->nextidFile );
+       if ( head->nextidFile )
+               ldbm_close( head->nextidFile );
 
 }
 
@@ -315,10 +323,11 @@ bdb2i_check_additional_attr_index( struct ldbminfo *li )
        struct dirent  *file;
 
        if ( ( datadir = opendir( li->li_directory ) ) == NULL ) {
+               int err = errno;
 
                Debug( LDAP_DEBUG_ANY,
        "bdb2i_check_additional_attr_index(): ERROR while opening datadir: %s\n",
-                               strerror( errno ), 0, 0 );
+                               strerror( err ), 0, 0 );
                return( 1 );
 
        }
@@ -476,7 +485,30 @@ bdb2i_put_nextid( BackendDB *be, ID id )
 }
 
 
-/*  BDB2 backend-private functions of ldbm_store and ldbm_delete  */
+/*  BDB2 backend-private functions of libldbm  */
+LDBM
+bdb2i_db_open(
+       char *name,
+       int type,
+       int rw,
+       int mode,
+       int dbcachesize )
+{
+       LDBM            ret = NULL;
+       DB_INFO         dbinfo;
+
+       memset( &dbinfo, 0, sizeof( dbinfo ));
+       if ( bdb2i_dbEnv.mp_info == NULL )
+               dbinfo.db_cachesize = dbcachesize;
+       dbinfo.db_pagesize  = DEFAULT_DB_PAGE_SIZE;
+       dbinfo.db_malloc    = ldbm_malloc;
+
+       (void) db_open( name, type, rw, mode, &bdb2i_dbEnv, &dbinfo, &ret );
+
+       return( ret );
+}
+
+
 int
 bdb2i_db_store( LDBM ldbm, Datum key, Datum data, int flags )
 {
@@ -595,11 +627,12 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch )
                        txn_do_abort = 1;
 
                }
+               key.flags = 0;
                return( key );
        } else {
                *dbch = dbci;
                if ( (*dbci->c_get)( dbci, &key, &data, DB_NEXT ) == 0 ) {
-                       if ( data.dptr ) free( data.dptr );
+                       ldbm_datum_free( ldbm, data );
                } else {
                        if ( txnid != NULL ) {
 
@@ -609,7 +642,8 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch )
                                txn_do_abort = 1;
 
                        }
-                       if ( key.dptr ) free( key.dptr );
+                       ldbm_datum_free( ldbm, key );
+                       key.flags = 0;
                        key.dptr = NULL;
                        key.dsize = 0;
                }
@@ -624,13 +658,13 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
 {
        Datum   data;
        int             rc;
-       void    *oldKey = key.dptr;
 
        ldbm_datum_init( data );
-       data.flags = DB_DBT_MALLOC;
+       ldbm_datum_free( ldbm, key );
+       key.flags = data.flags = DB_DBT_MALLOC;
 
        if ( (*dbcp->c_get)( dbcp, &key, &data, DB_NEXT ) == 0 ) {
-               if ( data.dptr ) free( data.dptr );
+               ldbm_datum_free( ldbm, data );
        } else {
                if ( txnid != NULL ) {
 
@@ -640,12 +674,11 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
                        txn_do_abort = 1;
 
                }
+               key.flags = 0;
                key.dptr = NULL;
                key.dsize = 0;
        }
 
-       if ( oldKey ) free( oldKey );
-
        return( key );
 }
 
@@ -664,8 +697,9 @@ bdb2i_start_transction( DB_TXNMGR *txmgr )
        txn_do_abort = 0;
 
        if (( rc = txn_begin( txmgr, NULL, &txnid )) != 0 ) {
+               int err = errno;
                Debug( LDAP_DEBUG_ANY, "bdb2i_start_transction failed: %d: errno=%s\n",
-                                       rc, strerror( errno ), 0 );
+                                       rc, strerror( err ), 0 );
 
                if ( txnid != NULL )
                        (void) txn_abort( txnid );
@@ -740,10 +774,7 @@ bdb2i_set_txn_checkpoint( DB_TXNMGR *txmgr, int forced )
                logsize = forced ? (u_int32_t) 0 : txn_max_pending_log;
                mins    = forced ? (u_int32_t) 0 : txn_max_pending_time;
 
-               ldap_pvt_thread_mutex_lock( &currenttime_mutex );
-               time( &currenttime );
-               now = currenttime;
-               ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
+               now = slap_get_time();
 
                rc = txn_checkpoint( txmgr, logsize, mins );