From 9f67a2e6c9cda4682cb91ed1a7c44962404c88b0 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sun, 8 Aug 1999 07:28:44 +0000 Subject: [PATCH] Separate put_nextid() out from next_id_write() in back-ldbm/nextid.c. Use it in tools/ldif2id2entry.c instead of making the NEXTID file "by hand". --- servers/slapd/back-ldbm/nextid.c | 18 +++++++++--------- servers/slapd/back-ldbm/proto-back-ldbm.h | 1 + servers/slapd/tools/ldif2id2entry.c | 14 +++----------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/servers/slapd/back-ldbm/nextid.c b/servers/slapd/back-ldbm/nextid.c index d0d259aba8..3e5b16ffbe 100644 --- a/servers/slapd/back-ldbm/nextid.c +++ b/servers/slapd/back-ldbm/nextid.c @@ -17,10 +17,13 @@ #include "slap.h" #include "back-ldbm.h" +/* All functions except put_nextid() obey ldbm_ignore_nextid_file. */ + static ID next_id_read( Backend *be ); -static int next_id_write( Backend *be, ID id ); static ID next_id_get_save( Backend *be, int do_save ); +#define next_id_write( be, id ) \ + (ldbm_ignore_nextid_file ? (be, id, 0) : put_nextid( be, id )) static ID next_id_read( Backend *be ) @@ -62,19 +65,16 @@ next_id_read( Backend *be ) return id; } -static int -next_id_write( Backend *be, ID id ) +int +put_nextid( Backend *be, ID id ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; char* file = li->li_nextid_file; FILE* fp; int rc; - if ( ldbm_ignore_nextid_file ) - return 0; - if ( (fp = fopen( file, "w" )) == NULL ) { - Debug( LDAP_DEBUG_ANY, "next_id_write(%ld): could not open \"%s\"\n", + Debug( LDAP_DEBUG_ANY, "put_nextid(%ld): could not open \"%s\"\n", id, file, 0 ); return -1; } @@ -82,13 +82,13 @@ next_id_write( Backend *be, ID id ) rc = 0; if ( fprintf( fp, "%ld\n", id ) == EOF ) { - Debug( LDAP_DEBUG_ANY, "next_id_write(%ld): cannot fprintf\n", + Debug( LDAP_DEBUG_ANY, "put_nextid(%ld): cannot fprintf\n", id, 0, 0 ); rc = -1; } if( fclose( fp ) != 0 ) { - Debug( LDAP_DEBUG_ANY, "next_id_write %ld: cannot fclose\n", + Debug( LDAP_DEBUG_ANY, "put_nextid %ld: cannot fclose\n", id, 0, 0 ); rc = -1; } diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index 8275b03752..f490e321ce 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -178,6 +178,7 @@ int ldbm_modify_internal LDAP_P((Backend *be, * nextid.c */ +int put_nextid LDAP_P(( Backend *be, ID id )); ID next_id LDAP_P(( Backend *be )); void next_id_return LDAP_P(( Backend *be, ID id )); ID next_id_get LDAP_P(( Backend *be )); diff --git a/servers/slapd/tools/ldif2id2entry.c b/servers/slapd/tools/ldif2id2entry.c index 5f171bdea8..bcde84ec0f 100644 --- a/servers/slapd/tools/ldif2id2entry.c +++ b/servers/slapd/tools/ldif2id2entry.c @@ -76,23 +76,15 @@ main( int argc, char **argv ) } } + maxid++; + put_nextid( be, maxid ); /* override ldbm_ignore_nextid_file */ + #ifdef SLAP_CLEANUP ldbm_cache_close( be, db ); #endif slap_shutdown(dbnum); - maxid++; - sprintf( line, "%s/NEXTID", - ((struct ldbminfo *) be->be_private)->li_directory ); - if ( (fp = fopen( line, "w" )) == NULL ) { - perror( line ); - fprintf( stderr, "Could not write next id %ld\n", maxid ); - } else { - fprintf( fp, "%ld\n", maxid ); - fclose( fp ); - } - slap_destroy(); return( EXIT_SUCCESS ); -- 2.39.5