12 #ifdef HAVE_SYS_PARAM_H
13 #include <sys/param.h>
16 #include "ldif2common.h"
17 #include "../back-bdb2/back-bdb2.h"
20 #define INDEXCMD "ldif2index-bdb2"
21 #define ID2ENTRYCMD "ldif2id2entry-bdb2"
22 #define ID2CHILDRENCMD "ldif2id2children-bdb2"
25 static void fork_child( char *prog, char *args[] );
26 static void wait4kids( int nkidval );
28 static int maxkids = 1;
32 main( int argc, char **argv )
37 char buf2[20], buf3[20];
46 struct berval *vals[2];
47 Avlnode *avltypes = NULL;
49 slap_ldif_init( argc, argv, LDIF2LDBM, "bdb2", SLAP_TOOL_MODE );
53 be = &backends[dbnum];
55 /* disable write sync'ing */
56 li = (struct ldbminfo *) be->be_private;
57 li->li_dbcachewsync = 0;
60 * generate the id2entry index
64 sprintf( cmd, "%s/%s", sbindir, ID2ENTRYCMD );
67 args[i++] = inputfile;
69 args[i++] = tailorfile;
71 sprintf( buf2, "%d", dbnum+1 );
74 sprintf( buf3, "%d", ldap_debug );
79 fork_child( cmd, args );
82 * generate the dn2id and id2children indexes
86 sprintf( cmd, "%s/%s", sbindir, ID2CHILDRENCMD );
89 args[i++] = inputfile;
91 args[i++] = tailorfile;
93 sprintf( buf2, "%d", dbnum+1 );
96 sprintf( buf3, "%d", ldap_debug );
101 fork_child( cmd, args );
106 * generate the attribute indexes
110 sprintf( cmd, "%s/%s", sbindir, INDEXCMD );
113 args[i++] = inputfile;
115 args[i++] = tailorfile;
117 sprintf( buf2, "%d", dbnum+1 );
120 sprintf( buf3, "%d", ldap_debug );
124 args[i++] = NULL; /* will hold the attribute name */
135 char *type, *val, *s;
137 int indexmask, syntaxmask;
139 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
143 len = strlen( line );
144 while ( lcur + len + 1 > lmax ) {
146 buf = (char *) ch_realloc( buf, lmax );
148 strcpy( buf + lcur, line );
153 if ( line[0] == '\n' || stop && buf && *buf ) {
157 while ( (linep = ldif_getline( &s )) != NULL ) {
159 if ( ldif_parse_line( linep, &type, &val, &vlen )
161 Debug( LDAP_DEBUG_PARSE,
162 "bad line %d in entry ending at line %d ignored\n",
163 elineno, lineno, 0 );
167 if ( !isascii( *type ) || isdigit( *type ) )
170 type = strdup( type );
171 if ( avl_insert( &avltypes, type, (AVL_CMP) strcasecmp,
172 avl_dup_error ) != 0 ) {
175 bdb2i_attr_masks( be->be_private, type,
176 &indexmask, &syntaxmask );
179 fork_child( cmd, args );
188 slap_shutdown(dbnum);
194 exit( EXIT_SUCCESS );
198 fork_child( char *prog, char *args[] )
202 wait4kids( maxkids );
204 switch ( pid = fork() ) {
206 execvp( prog, args );
207 fprintf( stderr, "%s: ", prog );
209 exit( EXIT_FAILURE );
212 case -1: /* trouble */
213 fprintf( stderr, "Could not fork to run %s\n", prog );
217 default: /* parent */
224 wait4kids( int nkidval )
229 while ( nkids >= nkidval ) {
231 p = (unsigned char *) &status;
232 if ( p[sizeof(int) - 1] == 0177 ) {
234 "stopping: child stopped with signal %d\n",
235 p[sizeof(int) - 2] );
236 } else if ( p[sizeof(int) - 1] != 0 ) {
238 "stopping: child terminated with signal %d\n",
239 p[sizeof(int) - 1] );
240 exit( p[sizeof(int) - 1] );
241 } else if ( p[sizeof(int) - 2] != 0 ) {
243 "stopping: child exited with status %d\n",
244 p[sizeof(int) - 2] );
245 exit( p[sizeof(int) - 2] );