]> git.sur5r.net Git - openldap/commitdiff
error message from be_entry_put tool backend function
authorPierangelo Masarati <ando@openldap.org>
Sat, 12 Jan 2002 16:00:51 +0000 (16:00 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 12 Jan 2002 16:00:51 +0000 (16:00 +0000)
servers/slapd/back-bdb/tools.c
servers/slapd/back-ldbm/tools.c
servers/slapd/backglue.c
servers/slapd/slap.h
servers/slapd/tools/slapadd.c

index 1b61a9843fe33a2a41fa795d0b1e92f22859e41c..a131ab0b45fe189504113762f112d01194940e9e 100644 (file)
@@ -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;
                }
        }
index 7706becff77006dbddbdc01d42409ca663bef1a1..f8858c485bc507920a8d45d90875f70103685f89 100644 (file)
@@ -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;
        }
 
index 11eca56d1328a55f4d3ecdb3e0a61b2e1694ba29..79f20b8f27ad67abdad5b15e51f0e241d9a6b0cb 100644 (file)
@@ -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
index 52d59d2064cf55629479d6b3bcc61ece471167e9..c65907d60eb023e3f743384fa0cd6d15971d8821 100644 (file)
@@ -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 ));
 
index e428b620014cde13583ee14a406c7f8bd69ea980..cf6f03821d909ad4026760132599f777ab7c70f6 100644 (file)
@@ -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;