]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldif2ldbm.c
Updated some items
[openldap] / servers / slapd / tools / ldif2ldbm.c
index 53c8fa008c9e14875aab5fcc848f29522648bb07..9cbdf52b378f9573bed46b992a53e29ccbdde2e4 100644 (file)
 #define ID2CHILDRENCMD         "ldif2id2children"
 #define MAXARGS                100
 
-int            ldap_debug;
-int            ldap_syslog;
-int            ldap_syslog_level;
-int            global_schemacheck;
-long           num_entries_sent;
-long           num_bytes_sent;
-int            active_threads;
-char           *default_referral;
-struct objclass        *global_oc;
-time_t         currenttime;
-pthread_t      listener_tid;
-pthread_mutex_t        num_sent_mutex;
-pthread_mutex_t        entry2str_mutex;
-pthread_mutex_t        active_threads_mutex;
-pthread_mutex_t        new_conn_mutex;
-pthread_mutex_t        currenttime_mutex;
-pthread_mutex_t        replog_mutex;
-pthread_mutex_t        ops_mutex;
-pthread_mutex_t        regex_mutex;
-
 static void fork_child( char *prog, char *args[] );
 static void    wait4kids( int nkidval );
 
@@ -61,7 +41,7 @@ main( int argc, char **argv )
 {
        int             i, stop, status;
        char            *linep, *buf, *sbindir;
-       char            *args[10];
+       char            *args[MAXARGS];
        char            buf2[20], buf3[20];
        char            line[BUFSIZ];
        char            cmd[MAXPATHLEN];
@@ -69,7 +49,9 @@ main( int argc, char **argv )
        int             lmax, lcur;
        int             dbnum;
        ID              id;
+       int             rc;
        Backend         *be = NULL;
+       struct ldbminfo *li;
        struct berval   bv;
        struct berval   *vals[2];
        Avlnode         *avltypes = NULL;
@@ -122,8 +104,13 @@ main( int argc, char **argv )
         * initialize stuff and figure out which backend we're dealing with
         */
 
-       init();
-       read_config( tailorfile, &be, NULL );
+       rc = slap_init(SLAP_TOOL_MODE, "ldif2ldbm");
+       if (rc != 0 ) {
+               fprintf( stderr, "ldif2ldbm: slap_init failed!\n");
+               exit(1);
+       }
+
+       read_config( tailorfile );
 
        if ( dbnum == -1 ) {
                for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
@@ -144,8 +131,15 @@ main( int argc, char **argv )
                fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
                exit( 1 );
        }
+
+       slap_startup(dbnum);
+
        be = &backends[dbnum];
 
+       /* disable write sync'ing */
+       li = (struct ldbminfo *) be->be_private;
+       li->li_dbcachewsync = 0;
+
        /*
         * generate the id2entry index
         */
@@ -224,6 +218,9 @@ main( int argc, char **argv )
                int             vlen, indexmask, syntaxmask;
                Datum           key, data;
 
+               ldbm_datum_init( key );
+               ldbm_datum_init( data );
+
                if ( fgets( line, sizeof(line), stdin ) != NULL ) {
                        int     len;
 
@@ -242,9 +239,9 @@ main( int argc, char **argv )
                        id++;
                        s = buf;
                        elineno = 0;
-                       while ( (linep = str_getline( &s )) != NULL ) {
+                       while ( (linep = ldif_getline( &s )) != NULL ) {
                                elineno++;
-                               if ( str_parse_line( linep, &type, &val, &vlen )
+                               if ( ldif_parse_line( linep, &type, &val, &vlen )
                                    != 0 ) {
                                        Debug( LDAP_DEBUG_PARSE,
                            "bad line %d in entry ending at line %d ignored\n",
@@ -272,10 +269,13 @@ main( int argc, char **argv )
                        lcur = 0;
                }
        }
-       (*be->be_close)( be );
+
+       slap_shutdown(dbnum);
 
        wait4kids( -1 );
 
+       slap_destroy();
+
        exit( 0 );
 }