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;
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 );
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;
}
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;
}
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;
}
}
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;
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;
}
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;
}
"<= 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;
}
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;
}
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 );
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",
}
}
- 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;