]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/nextid.c
silence warning
[openldap] / servers / slapd / back-ldbm / nextid.c
index 8ac43d944a13627e599f310e2a332f41e8413f73..d14c4c6688353ae062397a2b362a3a0e1fdb1ecc 100644 (file)
@@ -1,7 +1,7 @@
 /* nextid.c - keep track of the next id to be given out */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 
 #include <ac/string.h>
 #include <ac/socket.h>
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
+#include <ac/param.h>
 
 #include "slap.h"
 #include "back-ldbm.h"
 
-static ID
-next_id_read( Backend *be )
+static int
+next_id_read( Backend *be, ID *idp )
 {
-       ID id = NOID;
        Datum key, data;
        DBCache *db;
 
+       *idp = NOID;
+
        if ( (db = ldbm_cache_open( be, "nextid", LDBM_SUFFIX, LDBM_WRCREAT ))
            == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "backend", LDAP_LEVEL_CRIT,
-                          "next_id_read: could not open/create nextid%s\n", LDBM_SUFFIX ));
+               LDAP_LOG( BACK_LDBM, CRIT,
+                  "next_id_read: could not open/create nextid%s\n", LDBM_SUFFIX, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "Could not open/create nextid" LDBM_SUFFIX "\n",
                        0, 0, 0 );
 #endif
 
-               return( NOID );
+               return( -1 );
        }
 
        ldbm_datum_init( key );
-       key.dptr = (char *) &id;
+       key.dptr = (char *) idp;
        key.dsize = sizeof(ID);
 
        data = ldbm_cache_fetch( db, key );
 
        if( data.dptr != NULL ) {
-               AC_MEMCPY( &id, data.dptr, sizeof( ID ) );
+               AC_MEMCPY( idp, data.dptr, sizeof( ID ) );
                ldbm_datum_free( db->dbc_db, data );
 
        } else {
-               id = 1;
+               *idp = 1;
        }
 
        ldbm_cache_close( be, db );
-       return id;
+       return( 0 );
 }
 
-ID
+int
 next_id_write( Backend *be, ID id )
 {
-       struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        Datum key, data;
        DBCache *db;
        ID noid = NOID;
-       int flags;
+       int flags, rc = 0;
 
        if ( (db = ldbm_cache_open( be, "nextid", LDBM_SUFFIX, LDBM_WRCREAT ))
            == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "backend", LDAP_LEVEL_CRIT,
-                          "next_id_write: Could not open/create nextid%s\n", LDBM_SUFFIX ));
+               LDAP_LOG( BACK_LDBM, CRIT,
+                 "next_id_write: Could not open/create nextid%s\n", LDBM_SUFFIX, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY, "Could not open/create nextid" LDBM_SUFFIX "\n",
                    0, 0, 0 );
 #endif
 
-               return( NOID );
+               return( -1 );
        }
 
        ldbm_datum_init( key );
@@ -90,49 +87,50 @@ next_id_write( Backend *be, ID id )
 
        flags = LDBM_REPLACE;
        if ( ldbm_cache_store( db, key, data, flags ) != 0 ) {
-               id = NOID;
+               rc = -1;
        }
 
        ldbm_cache_close( be, db );
-       return id;
+       return( rc );
 }
 
-ID
-next_id_get( Backend *be )
+int
+next_id_get( Backend *be, ID *idp )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       ID id = NOID;
+       int rc = 0;
 
-       ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex );
+       *idp = NOID;
 
        if ( li->li_nextid == NOID ) {
-               li->li_nextid = next_id_read( be );
+               if ( ( rc = next_id_read( be, idp ) ) ) {
+                       return( rc );
+               }
+               li->li_nextid = *idp;
        }
 
-       id = li->li_nextid;
+       *idp = li->li_nextid;
 
-       ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex );
-       return id;
+       return( rc );
 }
 
-ID
-next_id( Backend *be )
+int
+next_id( Backend *be, ID *idp )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       ID id = NOID;
-
-       ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex );
+       int rc = 0;
 
        if ( li->li_nextid == NOID ) {
-               li->li_nextid = next_id_read( be );
+               if ( ( rc = next_id_read( be, idp ) ) ) {
+                       return( rc );
+               }
+               li->li_nextid = *idp;
        }
 
-       if ( li->li_nextid != NOID ) {
-               id = li->li_nextid++;
-
-               (void) next_id_write( be, li->li_nextid );
+       *idp = li->li_nextid++;
+       if ( next_id_write( be, li->li_nextid ) ) {
+               rc = -1;
        }
 
-       ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex );
-       return id;
+       return( rc );
 }