From: Pierangelo Masarati Date: Sat, 12 Jan 2002 16:00:51 +0000 (+0000) Subject: error message from be_entry_put tool backend function X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~175 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f8fb4aca7668c722f41941be719203aa8c298e12;p=openldap error message from be_entry_put tool backend function --- diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 1b61a9843f..a131ab0b45 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -112,7 +112,8 @@ Entry* bdb_tool_entry_get( BackendDB *be, ID id ) ID bdb_tool_entry_put( BackendDB *be, - Entry *e ) + Entry *e, + struct berval *text ) { int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; @@ -122,6 +123,10 @@ ID bdb_tool_entry_put( assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); + assert( text ); + assert( text->bv_val ); + assert( text->bv_val[0] == '\0' ); + Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 ); @@ -129,18 +134,23 @@ ID bdb_tool_entry_put( rc = txn_begin( bdb->bi_dbenv, NULL, &tid, bdb->bi_db_opflags ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "txn_begin failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", + text->bv_val, 0, 0 ); return NOID; } } rc = bdb_next_id( be, tid, &e->e_id ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "next_id failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: next_id failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); goto done; } @@ -152,26 +162,32 @@ ID bdb_tool_entry_put( pdn.bv_len = 0; rc = bdb_dn2id_add( be, tid, &pdn, e ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "dn2id_add failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); goto done; } /* id2entry index */ rc = bdb_id2entry_add( be, tid, e ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "id2entry_add failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: id2entry_add failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); goto done; } rc = bdb_index_entry_add( be, tid, e, e->e_attrs ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "index_entry_add failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: index_entry_add failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); goto done; } @@ -180,17 +196,23 @@ done: if( rc == 0 ) { rc = txn_commit( tid, 0 ); if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "txn_commit failed: %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: txn_commit failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", + text->bv_val, 0, 0 ); e->e_id = NOID; } } else { txn_abort( tid ); + snprintf( text->bv_val, text->bv_len, + "txn_aborted! %s (%d)", + db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: txn_aborted! %s (%d)\n", - db_strerror(rc), rc, 0 ); + "=> bdb_tool_entry_put: %s\n", + text->bv_val, 0, 0 ); e->e_id = NOID; } } diff --git a/servers/slapd/back-ldbm/tools.c b/servers/slapd/back-ldbm/tools.c index 7706becff7..f8858c485b 100644 --- a/servers/slapd/back-ldbm/tools.c +++ b/servers/slapd/back-ldbm/tools.c @@ -166,7 +166,8 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id ) ID ldbm_tool_entry_put( BackendDB *be, - Entry *e ) + Entry *e, + struct berval *text ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; Datum key, data; @@ -176,7 +177,12 @@ ID ldbm_tool_entry_put( assert( slapMode & SLAP_TOOL_MODE ); assert( id2entry != NULL ); + assert( text ); + assert( text->bv_val ); + assert( text->bv_val[0] == '\0' ); + if ( next_id_get( be, &id ) || id == NOID ) { + strncpy( text->bv_val, "unable to get nextid", text->bv_len ); return NOID; } @@ -192,6 +198,7 @@ ID ldbm_tool_entry_put( if ( dn2id( be, &e->e_nname, &id ) ) { /* something bad happened to ldbm cache */ + strncpy( text->bv_val, "ldbm cache corrupted", text->bv_len ); return NOID; } @@ -205,16 +212,19 @@ ID ldbm_tool_entry_put( "<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n", e->e_ndn, id, 0 ); #endif + strncpy( text->bv_val, "already exists", text->bv_len ); return NOID; } rc = index_entry_add( be, e, e->e_attrs ); if( rc != 0 ) { + strncpy( text->bv_val, "index add failed", text->bv_len ); return NOID; } rc = dn2id_add( be, &e->e_nname, e->e_id ); if( rc != 0 ) { + strncpy( text->bv_val, "dn2id add failed", text->bv_len ); return NOID; } @@ -237,6 +247,7 @@ ID ldbm_tool_entry_put( if( rc != 0 ) { (void) dn2id_delete( be, &e->e_nname, e->e_id ); + strncpy( text->bv_val, "cache store failed", text->bv_len ); return NOID; } diff --git a/servers/slapd/backglue.c b/servers/slapd/backglue.c index 11eca56d13..79f20b8f27 100644 --- a/servers/slapd/backglue.c +++ b/servers/slapd/backglue.c @@ -717,7 +717,8 @@ glue_tool_entry_get ( static ID glue_tool_entry_put ( BackendDB *b0, - Entry *e + Entry *e, + struct berval *text ) { BackendDB *be; @@ -742,7 +743,7 @@ glue_tool_entry_put ( return NOID; } glueBack = be; - return be->be_entry_put (be, e); + return be->be_entry_put (be, e, text); } static int diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 52d59d2064..c65907d60e 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1205,7 +1205,8 @@ typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be )); typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be )); typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be )); typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id )); -typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e )); +typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, + struct berval *text )); typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id )); typedef int (BI_tool_sync) LDAP_P(( BackendDB *be )); diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index e428b62001..cf6f03821d 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -28,7 +28,7 @@ main( int argc, char **argv ) int rc = EXIT_SUCCESS; const char *text; - char textbuf[SLAP_TEXT_BUFLEN]; + char textbuf[SLAP_TEXT_BUFLEN] = { '\0' }; size_t textlen = sizeof textbuf; slap_tool_init( "slapadd", SLAPADD, argc, argv ); @@ -55,6 +55,8 @@ main( int argc, char **argv ) while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) { ID id; Entry *e = str2entry( buf ); + char buf[1024]; + struct berval bvtext = { textlen, textbuf }; if( e == NULL ) { fprintf( stderr, "%s: could not parse entry (line=%d)\n", @@ -146,10 +148,10 @@ main( int argc, char **argv ) } } - id = be->be_entry_put( be, e ); + id = be->be_entry_put( be, e, &bvtext ); if( id == NOID ) { - fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n", - progname, e->e_dn, lineno ); + fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n", + progname, e->e_dn, lineno, bvtext.bv_val ); rc = EXIT_FAILURE; entry_free( e ); if( continuemode ) continue;