From: Kurt Spanier Date: Mon, 22 Feb 1999 11:28:01 +0000 (+0000) Subject: Client programs for test008-concurrency moved to subdir tests/progs. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~550 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2889c67adf7e0f88d6b8c704bea3c4a9e46ba61c;p=openldap Client programs for test008-concurrency moved to subdir tests/progs. Building tests/progs/*.c in the main build process. ==> Test-suite must be called by 'make test', or 'make test-bdb2' --- diff --git a/Makefile.in b/Makefile.in index aaac8d6503..f832bd07e9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,8 +9,8 @@ ## in file LICENSE in the top-level directory of the distribution. ## -SUBDIRS= include libraries clients servers # contrib -CLEANDIRS= tests doc +SUBDIRS= include libraries clients servers tests # contrib +CLEANDIRS= doc # tests doc INSTALLDIRS= doc makefiles: FORCE diff --git a/configure b/configure index 573fb573d3..4361158c11 100755 --- a/configure +++ b/configure @@ -9830,7 +9830,8 @@ servers/slapd/back-tcl/Makefile:build/top.mk:servers/slapd/back-tcl/Makefile.in: servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \ servers/slapd/tools/Makefile:build/top.mk:servers/slapd/tools/Makefile.in \ servers/slurpd/Makefile:build/top.mk:servers/slurpd/Makefile.in:build/srv.mk \ -tests/Makefile:build/top.mk:tests/Makefile.in \ +tests/Makefile:build/top.mk:tests/Makefile.in:build/dir.mk \ +tests/progs/Makefile:build/top.mk:tests/progs/Makefile.in:build/rules.mk \ include/portable.h include/ldap_features.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF diff --git a/configure.in b/configure.in index 5b49908715..95f79d2982 100644 --- a/configure.in +++ b/configure.in @@ -1691,7 +1691,8 @@ servers/slapd/back-tcl/Makefile:build/top.mk:servers/slapd/back-tcl/Makefile.in: servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \ servers/slapd/tools/Makefile:build/top.mk:servers/slapd/tools/Makefile.in \ servers/slurpd/Makefile:build/top.mk:servers/slurpd/Makefile.in:build/srv.mk \ -tests/Makefile:build/top.mk:tests/Makefile.in \ +tests/Makefile:build/top.mk:tests/Makefile.in:build/dir.mk \ +tests/progs/Makefile:build/top.mk:tests/progs/Makefile.in:build/rules.mk \ ,[ date > stamp-h echo Please \"make depend\" to build dependencies diff --git a/tests/Makefile.in b/tests/Makefile.in index 7b4e633109..474ede5a79 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -2,34 +2,11 @@ ## COPYING RESTRICTIONS APPLY, see COPYRIGHT file ## ## tests Makefile.in for OpenLDAP -BUILD_BDB2 = @BUILD_BDB2@ - -SRC = slapd-tester.c slapd-search.c -PROGRAMS = slapd-tester slapd-search slapd-read slapd-addel - -LDAP_INCDIR= ../include -LDAP_LIBDIR= ../libraries - -XLIBS = -lldap_r -llber -llutil - -build-tools: FORCE - $(MAKE) $(MFLAGS) load-tools +SUBDIRS= progs -load-tools: $(PROGRAMS) - -slapd-tester: slapd-tester.o - $(LTLINK) -o $@ slapd-tester.o - -slapd-search: slapd-search.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) - $(LTLINK) -o $@ slapd-search.o $(LIBS) - -slapd-read: slapd-read.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) - $(LTLINK) -o $@ slapd-read.o $(LIBS) - -slapd-addel: slapd-addel.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) - $(LTLINK) -o $@ slapd-addel.o $(LIBS) +BUILD_BDB2 = @BUILD_BDB2@ -bdb2-local: build-tools FORCE +test-bdb2: FORCE @if test "$(BUILD_BDB2)" = "yes" ; then \ $(LN_S) $(srcdir)/data . ; \ echo "Initiating LDAP tests..." ; \ @@ -39,7 +16,8 @@ bdb2-local: build-tools FORCE echo "run configure with --enable-bdb2" ; \ fi -all-local: build-tools FORCE +test: test-ldbm +test-ldbm: FORCE @-$(LN_S) $(srcdir)/data . @echo "Initiating LDAP tests..."; \ $(MKDIR) test-db test-repl ; \ diff --git a/tests/data/slapd-bdb2-master.conf b/tests/data/slapd-bdb2-master.conf index 2dad68bfc0..374f7881ec 100644 --- a/tests/data/slapd-bdb2-master.conf +++ b/tests/data/slapd-bdb2-master.conf @@ -13,7 +13,7 @@ argsfile ./test-db/slapd.args backend bdb2 home ./test-db -mpoolsize 2100000 +mpoolsize 21000000 database bdb2 cachesize 4 diff --git a/tests/progs/Makefile.in b/tests/progs/Makefile.in new file mode 100644 index 0000000000..6e5bcb19d6 --- /dev/null +++ b/tests/progs/Makefile.in @@ -0,0 +1,31 @@ +## Copyright 1998 The OpenLDAP Foundation, All Rights Reserved. +## COPYING RESTRICTIONS APPLY, see COPYRIGHT file +## +## tests Makefile.in for OpenLDAP + +PROGRAMS = slapd-tester slapd-search slapd-read slapd-addel +SRCS = slapd-tester.c slapd-search.c slapd-read.c slapd-addel.c + +LDAP_INCDIR= ../../include +LDAP_LIBDIR= ../../libraries + +XLIBS = -lldap -llber -llutil + +# build-tools: FORCE +# $(MAKE) $(MFLAGS) load-tools + +# load-tools: $(PROGRAMS) + +slapd-tester: slapd-tester.o + $(LTLINK) -o $@ slapd-tester.o + +slapd-search: slapd-search.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) + $(LTLINK) -o $@ slapd-search.o $(LIBS) + +slapd-read: slapd-read.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) + $(LTLINK) -o $@ slapd-read.o $(LIBS) + +slapd-addel: slapd-addel.o $(LDAP_LIBLBER_DEPEND) $(LDAP_LIBLDAP_DEPEND) + $(LTLINK) -o $@ slapd-addel.o $(LIBS) + + diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c new file mode 100644 index 0000000000..e99fbf00fe --- /dev/null +++ b/tests/progs/slapd-addel.c @@ -0,0 +1,280 @@ +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include "lber.h" +#include "ldap.h" + +#define LOOPS 100 + +static char * +get_add_entry( char *filename, LDAPMod ***mods ); + +static void +do_addel( char *host, int port, char *manager, char *passwd, + char *dn, LDAPMod **attrs, int maxloop ); + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s [-h ] -p port -D -w -f [-l ]\n", + name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, j; + char *host = "localhost"; + int port = -1; + char *manager = NULL; + char *passwd = NULL; + char *filename = NULL; + char *entry = NULL; + int loops = LOOPS; + LDAPMod **attrs = NULL; + + while ( (i = getopt( argc, argv, "h:p:D:w:f:l:" )) != EOF ) { + switch( i ) { + case 'h': /* the servers host */ + host = strdup( optarg ); + break; + + case 'p': /* the servers port */ + port = atoi( optarg ); + break; + + case 'D': /* the servers manager */ + manager = strdup( optarg ); + break; + + case 'w': /* the server managers password */ + passwd = strdup( optarg ); + break; + + case 'f': /* file with entry search request */ + filename = strdup( optarg ); + break; + + case 'l': /* the number of loops */ + loops = atoi( optarg ); + break; + + default: + usage( argv[0] ); + break; + } + } + + if (( filename == NULL ) || ( port == -1 ) || + ( manager == NULL ) || ( passwd == NULL )) + usage( argv[0] ); + + entry = get_add_entry( filename, &attrs ); + if (( entry == NULL ) || ( *entry == '\0' )) { + + fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n", + argv[0], filename ); + exit( 1 ); + + } + + if (( attrs == NULL ) || ( *attrs == '\0' )) { + + fprintf( stderr, "%s: invalid attrs in file \"%s\".\n", + argv[0], filename ); + exit( 1 ); + + } + + do_addel( host, port, manager, passwd, entry, attrs, loops ); + + exit( 0 ); +} + + +#define safe_realloc( ptr, size ) ( ptr == NULL ? malloc( size ) : \ + realloc( ptr, size )) + + +static void +addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) +{ + LDAPMod **pmods; + int i, j; + struct berval *bvp; + + pmods = *pmodsp; + modop |= LDAP_MOD_BVALUES; + + i = 0; + if ( pmods != NULL ) { + for ( ; pmods[ i ] != NULL; ++i ) { + if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 && + pmods[ i ]->mod_op == modop ) { + break; + } + } + } + + if ( pmods == NULL || pmods[ i ] == NULL ) { + if (( pmods = (LDAPMod **)safe_realloc( pmods, (i + 2) * + sizeof( LDAPMod * ))) == NULL ) { + perror( "safe_realloc" ); + exit( 1 ); + } + *pmodsp = pmods; + pmods[ i + 1 ] = NULL; + if (( pmods[ i ] = (LDAPMod *)calloc( 1, sizeof( LDAPMod ))) + == NULL ) { + perror( "calloc" ); + exit( 1 ); + } + pmods[ i ]->mod_op = modop; + if (( pmods[ i ]->mod_type = strdup( attr )) == NULL ) { + perror( "strdup" ); + exit( 1 ); + } + } + + if ( value != NULL ) { + j = 0; + if ( pmods[ i ]->mod_bvalues != NULL ) { + for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { + ; + } + } + if (( pmods[ i ]->mod_bvalues = + (struct berval **)safe_realloc( pmods[ i ]->mod_bvalues, + (j + 2) * sizeof( struct berval * ))) == NULL ) { + perror( "safe_realloc" ); + exit( 1 ); + } + pmods[ i ]->mod_bvalues[ j + 1 ] = NULL; + if (( bvp = (struct berval *)malloc( sizeof( struct berval ))) + == NULL ) { + perror( "malloc" ); + exit( 1 ); + } + pmods[ i ]->mod_bvalues[ j ] = bvp; + + bvp->bv_len = vlen; + if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) { + perror( "malloc" ); + exit( 1 ); + } + SAFEMEMCPY( bvp->bv_val, value, vlen ); + bvp->bv_val[ vlen ] = '\0'; + } +} + + +static char * +get_add_entry( char *filename, LDAPMod ***mods ) +{ + FILE *fp; + char *entry = NULL; + + if ( fp = fopen( filename, "r" )) { + char line[BUFSIZ]; + + if ( fgets( line, BUFSIZ, fp )) { + char *nl; + + if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) + *nl = '\0'; + entry = strdup( line ); + + } + + while ( fgets( line, BUFSIZ, fp )) { + char *nl; + char *value; + + if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) + *nl = '\0'; + + if ( *line == '\0' ) break; + if ( !( value = strchr( line, ':' ))) break; + + *value++ = '\0'; + while ( *value && isspace( *value )) value++; + + addmodifyop( mods, LDAP_MOD_ADD, line, value, strlen( value )); + + } + fclose( fp ); + } + + return( entry ); +} + + +static void +do_addel( + char *host, + int port, + char *manager, + char *passwd, + char *entry, + LDAPMod **attrs, + int maxloop +) +{ + LDAP *ld; + int i; + pid_t pid = getpid(); + + if (( ld = ldap_init( host, port )) == NULL ) { + perror( "ldap_init" ); + exit( 1 ); + } + + if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) + != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_bind" ); + exit( 1 ); + } + + + fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n", + pid, maxloop, entry ); + + for ( i = 0; i < maxloop; i++ ) { + + /* add the entry */ + if ( ldap_add_s( ld, entry, attrs ) != LDAP_SUCCESS ) { + + ldap_perror( ld, "ldap_add" ); + break; + + } + + /* wait a second for the add to really complete */ + sleep( 1 ); + + /* now delete the entry again */ + if ( ldap_delete_s( ld, entry ) != LDAP_SUCCESS ) { + + ldap_perror( ld, "ldap_delete" ); + break; + + } + + } + + fprintf( stderr, " PID=%ld - Add/Delete done.\n", pid ); + + ldap_unbind( ld ); +} + + diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c new file mode 100644 index 0000000000..b94ec3e705 --- /dev/null +++ b/tests/progs/slapd-read.c @@ -0,0 +1,123 @@ +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include "lber.h" +#include "ldap.h" + +#define LOOPS 100 + +static void +do_read( char *host, int port, char *entry, int maxloop ); + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s [-h ] -p port -e [-l ]\n", + name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, j; + char *host = "localhost"; + int port = -1; + char *entry = NULL; + int loops = LOOPS; + + while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) { + switch( i ) { + case 'h': /* the servers host */ + host = strdup( optarg ); + break; + + case 'p': /* the servers port */ + port = atoi( optarg ); + break; + + case 'e': /* file with entry search request */ + entry = strdup( optarg ); + break; + + case 'l': /* the number of loops */ + loops = atoi( optarg ); + break; + + default: + usage( argv[0] ); + break; + } + } + + if (( entry == NULL ) || ( port == -1 )) + usage( argv[0] ); + + if ( *entry == '\0' ) { + + fprintf( stderr, "%s: invalid EMPTY entry DN.\n", + argv[0] ); + exit( 1 ); + + } + + do_read( host, port, entry, ( 4 * loops )); + + exit( 0 ); +} + + +static void +do_read( char *host, int port, char *entry, int maxloop ) +{ + LDAP *ld; + int i; + char *attrs[] = { "cn", "sn", NULL }; + char *filter = "(objectclass=*)"; + pid_t pid = getpid(); + + if (( ld = ldap_init( host, port )) == NULL ) { + perror( "ldap_init" ); + exit( 1 ); + } + + if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_bind" ); + exit( 1 ); + } + + + fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n", + pid, maxloop, entry ); + + for ( i = 0; i < maxloop; i++ ) { + LDAPMessage *res; + int rc; + + if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE, + filter, attrs, 0, &res )) != LDAP_SUCCESS ) { + + ldap_perror( ld, "ldap_read" ); + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; + + } + + ldap_msgfree( res ); + } + + fprintf( stderr, " PID=%ld - Read done.\n", pid ); + + ldap_unbind( ld ); +} + + diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c new file mode 100644 index 0000000000..27fc421be4 --- /dev/null +++ b/tests/progs/slapd-search.c @@ -0,0 +1,127 @@ +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include "lber.h" +#include "ldap.h" + +#define LOOPS 100 + +static void +do_search( char *host, int port, char *sbase, char *filter, int maxloop ); + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s [-h ] -p port -b -f [-l ]\n", + name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, j; + char *host = "localhost"; + int port = -1; + char *sbase = NULL; + char *filter = NULL; + int loops = LOOPS; + + while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) { + switch( i ) { + case 'h': /* the servers host */ + host = strdup( optarg ); + break; + + case 'p': /* the servers port */ + port = atoi( optarg ); + break; + + case 'b': /* file with search base */ + sbase = strdup( optarg ); + break; + + case 'f': /* the search request */ + filter = strdup( optarg ); + break; + + case 'l': /* number of loops */ + loops = atoi( optarg ); + break; + + default: + usage( argv[0] ); + break; + } + } + + if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 )) + usage( argv[0] ); + + if ( *filter == '\0' ) { + + fprintf( stderr, "%s: invalid EMPTY search filter.\n", + argv[0] ); + exit( 1 ); + + } + + do_search( host, port, sbase, filter, ( 4 * loops )); + + exit( 0 ); +} + + +static void +do_search( char *host, int port, char *sbase, char *filter, int maxloop ) +{ + LDAP *ld; + int i; + char *attrs[] = { "cn", "sn", NULL }; + pid_t pid = getpid(); + + if (( ld = ldap_init( host, port )) == NULL ) { + perror( "ldap_init" ); + exit( 1 ); + } + + if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_bind" ); + exit( 1 ); + } + + + fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n", + pid, maxloop, sbase, filter ); + + for ( i = 0; i < maxloop; i++ ) { + LDAPMessage *res; + int rc; + + if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, + filter, attrs, 0, &res )) != LDAP_SUCCESS ) { + + ldap_perror( ld, "ldap_search" ); + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; + + } + + ldap_msgfree( res ); + } + + fprintf( stderr, " PID=%ld - Search done.\n", pid ); + + ldap_unbind( ld ); +} + + diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c new file mode 100644 index 0000000000..2d63a1d9ee --- /dev/null +++ b/tests/progs/slapd-tester.c @@ -0,0 +1,357 @@ +#include "portable.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "ldapconfig.h" + + +#define SEARCHCMD "slapd-search" +#define READCMD "slapd-read" +#define ADDCMD "slapd-addel" +#define MAXARGS 100 +#define MAXREQS 20 +#define LOOPS "100" + +#define TSEARCHFILE "do_search.0" +#define TREADFILE "do_read.0" +#define TADDFILE "do_add." + +static char *get_file_name( char *dirname, char *filename ); +static int get_search_filters( char *filename, char *filters[] ); +static int get_read_entries( char *filename, char *entries[] ); +static void fork_child( char *prog, char *args[] ); +static void wait4kids( int nkidval ); + +static int maxkids = 20; +static int nkids; + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s [-h ] -p -D -w -d -b [-j ] [-l ] -P \n", name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, j; + char *host = "localhost"; + char *port = NULL; + char *manager = NULL; + char *passwd = NULL; + char *dirname = NULL; + char *sbase = NULL; + char *progdir = NULL; + char *loops = LOOPS; + DIR *datadir; + struct dirent *file; + char *sfile = NULL; + char *sreqs[MAXREQS]; + int snum = 0; + char *rfile = NULL; + char *rreqs[MAXREQS]; + int rnum = 0; + char *afiles[MAXREQS]; + int anum = 0; + char *sargs[MAXARGS]; + int sanum; + char scmd[MAXPATHLEN]; + char *rargs[MAXARGS]; + int ranum; + char rcmd[MAXPATHLEN]; + char *aargs[MAXARGS]; + int aanum; + char acmd[MAXPATHLEN]; + + while ( (i = getopt( argc, argv, "h:p:D:w:b:d:j:l:P:" )) != EOF ) { + switch( i ) { + case 'h': /* slapd host */ + host = strdup( optarg ); + break; + + case 'p': /* the servers port number */ + port = strdup( optarg ); + break; + + case 'D': /* slapd manager */ + manager = strdup( optarg ); + break; + + case 'w': /* the managers passwd */ + passwd = strdup( optarg ); + break; + + case 'b': /* the base DN */ + sbase = strdup( optarg ); + break; + + case 'd': /* data directory */ + dirname = strdup( optarg ); + break; + + case 'P': /* prog directory */ + progdir = strdup( optarg ); + break; + + case 'j': /* the number of parallel clients */ + maxkids = atoi( optarg ); + break; + + case 'l': /* the number of loops per client */ + loops = strdup( optarg ); + break; + + default: + usage( argv[0] ); + break; + } + } + + if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL ) || + ( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL )) + usage( argv[0] ); + + /* get the file list */ + if ( ( datadir = opendir( dirname )) == NULL ) { + + fprintf( stderr, "%s: couldn't open data directory \"%s\".\n", + argv[0], dirname ); + exit( 1 ); + + } + + /* look for search, read, and add/delete files */ + for ( file = readdir( datadir ); file; file = readdir( datadir )) { + + if ( !strcasecmp( file->d_name, TSEARCHFILE )) { + sfile = get_file_name( dirname, file->d_name ); + continue; + } else if ( !strcasecmp( file->d_name, TREADFILE )) { + rfile = get_file_name( dirname, file->d_name ); + continue; + } else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE )) + && ( anum < MAXREQS )) { + afiles[anum++] = get_file_name( dirname, file->d_name ); + continue; + } + } + + /* look for search requests */ + if ( sfile ) { + snum = get_search_filters( sfile, sreqs ); + } + + /* look for read requests */ + if ( rfile ) { + rnum = get_read_entries( rfile, rreqs ); + } + + /* + * generate the search clients + */ + + sanum = 0; + sprintf( scmd, "%s%s%s", progdir, DEFAULT_DIRSEP, SEARCHCMD ); + sargs[sanum++] = scmd; + sargs[sanum++] = "-h"; + sargs[sanum++] = host; + sargs[sanum++] = "-p"; + sargs[sanum++] = port; + sargs[sanum++] = "-b"; + sargs[sanum++] = sbase; + sargs[sanum++] = "-l"; + sargs[sanum++] = loops; + sargs[sanum++] = "-f"; + sargs[sanum++] = NULL; /* will hold the search request */ + sargs[sanum++] = NULL; + + /* + * generate the read clients + */ + + ranum = 0; + sprintf( rcmd, "%s%s%s", progdir, DEFAULT_DIRSEP, READCMD ); + rargs[ranum++] = rcmd; + rargs[ranum++] = "-h"; + rargs[ranum++] = host; + rargs[ranum++] = "-p"; + rargs[ranum++] = port; + rargs[ranum++] = "-l"; + rargs[ranum++] = loops; + rargs[ranum++] = "-e"; + rargs[ranum++] = NULL; /* will hold the read entry */ + rargs[ranum++] = NULL; + + /* + * generate the add/delete clients + */ + + aanum = 0; + sprintf( acmd, "%s%s%s", progdir, DEFAULT_DIRSEP, ADDCMD ); + aargs[aanum++] = acmd; + aargs[aanum++] = "-h"; + aargs[aanum++] = host; + aargs[aanum++] = "-p"; + aargs[aanum++] = port; + aargs[aanum++] = "-D"; + aargs[aanum++] = manager; + aargs[aanum++] = "-w"; + aargs[aanum++] = passwd; + aargs[aanum++] = "-l"; + aargs[aanum++] = loops; + aargs[aanum++] = "-f"; + aargs[aanum++] = NULL; /* will hold the add data file */ + aargs[aanum++] = NULL; + + for ( j = 0; j < MAXREQS; j++ ) { + + if ( j < snum ) { + + sargs[sanum - 2] = sreqs[j]; + fork_child( scmd, sargs ); + + } + + if ( j < rnum ) { + + rargs[ranum - 2] = rreqs[j]; + fork_child( rcmd, rargs ); + + } + + if ( j < anum ) { + + aargs[aanum - 2] = afiles[j]; + fork_child( acmd, aargs ); + + } + + } + + wait4kids( -1 ); + + exit( 0 ); +} + +static char * +get_file_name( char *dirname, char *filename ) +{ + char buf[MAXPATHLEN]; + + sprintf( buf, "%s%s%s", dirname, DEFAULT_DIRSEP, filename ); + return( strdup( buf )); +} + + +static int +get_search_filters( char *filename, char *filters[] ) +{ + FILE *fp; + int filter = 0; + + if ( fp = fopen( filename, "r" )) { + char line[BUFSIZ]; + + while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { + char *nl; + + if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) + *nl = '\0'; + filters[filter++] = strdup( line ); + + } + fclose( fp ); + } + + return( filter ); +} + + +static int +get_read_entries( char *filename, char *entries[] ) +{ + FILE *fp; + int entry = 0; + + if ( fp = fopen( filename, "r" )) { + char line[BUFSIZ]; + + while (( entry < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { + char *nl; + + if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) + *nl = '\0'; + entries[entry++] = strdup( line ); + + } + fclose( fp ); + } + + return( entry ); +} + + +static void +fork_child( char *prog, char *args[] ) +{ + int status, pid; + + wait4kids( maxkids ); + + switch ( pid = fork() ) { + case 0: /* child */ + execvp( prog, args ); + fprintf( stderr, "%s: ", prog ); + perror( "execv" ); + exit( -1 ); + break; + + case -1: /* trouble */ + fprintf( stderr, "Could not fork to run %s\n", prog ); + perror( "fork" ); + break; + + default: /* parent */ + nkids++; + break; + } +} + +static void +wait4kids( int nkidval ) +{ + int status; + unsigned char *p; + + while ( nkids >= nkidval ) { + wait( &status ); + p = (unsigned char *) &status; + if ( p[sizeof(int) - 1] == 0177 ) { + fprintf( stderr, + "stopping: child stopped with signal %d\n", + p[sizeof(int) - 2] ); + } else if ( p[sizeof(int) - 1] != 0 ) { + fprintf( stderr, + "stopping: child terminated with signal %d\n", + p[sizeof(int) - 1] ); + exit( p[sizeof(int) - 1] ); + } else if ( p[sizeof(int) - 2] != 0 ) { + fprintf( stderr, + "stopping: child exited with status %d\n", + p[sizeof(int) - 2] ); + exit( p[sizeof(int) - 2] ); + } else { + nkids--; + } + } +} diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh index a03422aab2..803405b3f1 100755 --- a/tests/scripts/defines.sh +++ b/tests/scripts/defines.sh @@ -10,6 +10,7 @@ else fi DATADIR=$SRCDIR/data +PROGDIR=$SRCDIR/progs if test "$BACKEND" = "bdb2" ; then LDIF2LDBM=../servers/slapd/tools/ldif2ldbm-bdb2 @@ -31,7 +32,7 @@ SLURPD=../servers/slurpd/slurpd LDAPSEARCH=../clients/tools/ldapsearch LDAPMODIFY=../clients/tools/ldapmodify LDAPADD=../clients/tools/ldapadd -SLAPDTESTER=./slapd-tester +SLAPDTESTER=$PROGDIR/slapd-tester LVL=5 PORT=9009 SLAVEPORT=9010 diff --git a/tests/scripts/test008-concurrency b/tests/scripts/test008-concurrency index 88355b20e1..df78da1a56 100755 --- a/tests/scripts/test008-concurrency +++ b/tests/scripts/test008-concurrency @@ -38,7 +38,7 @@ echo "Waiting 5 seconds for slapd to start..." sleep 5 echo "Using tester for concurrent server access..." -$SLAPDTESTER -b "$BASEDN" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50 +$SLAPDTESTER -b "$BASEDN" -P "$PROGDIR" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50 RC=$? if [ $RC != 0 ]; then diff --git a/tests/slapd-addel.c b/tests/slapd-addel.c deleted file mode 100644 index e99fbf00fe..0000000000 --- a/tests/slapd-addel.c +++ /dev/null @@ -1,280 +0,0 @@ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include "lber.h" -#include "ldap.h" - -#define LOOPS 100 - -static char * -get_add_entry( char *filename, LDAPMod ***mods ); - -static void -do_addel( char *host, int port, char *manager, char *passwd, - char *dn, LDAPMod **attrs, int maxloop ); - -static void -usage( char *name ) -{ - fprintf( stderr, "usage: %s [-h ] -p port -D -w -f [-l ]\n", - name ); - exit( 1 ); -} - -int -main( int argc, char **argv ) -{ - int i, j; - char *host = "localhost"; - int port = -1; - char *manager = NULL; - char *passwd = NULL; - char *filename = NULL; - char *entry = NULL; - int loops = LOOPS; - LDAPMod **attrs = NULL; - - while ( (i = getopt( argc, argv, "h:p:D:w:f:l:" )) != EOF ) { - switch( i ) { - case 'h': /* the servers host */ - host = strdup( optarg ); - break; - - case 'p': /* the servers port */ - port = atoi( optarg ); - break; - - case 'D': /* the servers manager */ - manager = strdup( optarg ); - break; - - case 'w': /* the server managers password */ - passwd = strdup( optarg ); - break; - - case 'f': /* file with entry search request */ - filename = strdup( optarg ); - break; - - case 'l': /* the number of loops */ - loops = atoi( optarg ); - break; - - default: - usage( argv[0] ); - break; - } - } - - if (( filename == NULL ) || ( port == -1 ) || - ( manager == NULL ) || ( passwd == NULL )) - usage( argv[0] ); - - entry = get_add_entry( filename, &attrs ); - if (( entry == NULL ) || ( *entry == '\0' )) { - - fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n", - argv[0], filename ); - exit( 1 ); - - } - - if (( attrs == NULL ) || ( *attrs == '\0' )) { - - fprintf( stderr, "%s: invalid attrs in file \"%s\".\n", - argv[0], filename ); - exit( 1 ); - - } - - do_addel( host, port, manager, passwd, entry, attrs, loops ); - - exit( 0 ); -} - - -#define safe_realloc( ptr, size ) ( ptr == NULL ? malloc( size ) : \ - realloc( ptr, size )) - - -static void -addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) -{ - LDAPMod **pmods; - int i, j; - struct berval *bvp; - - pmods = *pmodsp; - modop |= LDAP_MOD_BVALUES; - - i = 0; - if ( pmods != NULL ) { - for ( ; pmods[ i ] != NULL; ++i ) { - if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 && - pmods[ i ]->mod_op == modop ) { - break; - } - } - } - - if ( pmods == NULL || pmods[ i ] == NULL ) { - if (( pmods = (LDAPMod **)safe_realloc( pmods, (i + 2) * - sizeof( LDAPMod * ))) == NULL ) { - perror( "safe_realloc" ); - exit( 1 ); - } - *pmodsp = pmods; - pmods[ i + 1 ] = NULL; - if (( pmods[ i ] = (LDAPMod *)calloc( 1, sizeof( LDAPMod ))) - == NULL ) { - perror( "calloc" ); - exit( 1 ); - } - pmods[ i ]->mod_op = modop; - if (( pmods[ i ]->mod_type = strdup( attr )) == NULL ) { - perror( "strdup" ); - exit( 1 ); - } - } - - if ( value != NULL ) { - j = 0; - if ( pmods[ i ]->mod_bvalues != NULL ) { - for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { - ; - } - } - if (( pmods[ i ]->mod_bvalues = - (struct berval **)safe_realloc( pmods[ i ]->mod_bvalues, - (j + 2) * sizeof( struct berval * ))) == NULL ) { - perror( "safe_realloc" ); - exit( 1 ); - } - pmods[ i ]->mod_bvalues[ j + 1 ] = NULL; - if (( bvp = (struct berval *)malloc( sizeof( struct berval ))) - == NULL ) { - perror( "malloc" ); - exit( 1 ); - } - pmods[ i ]->mod_bvalues[ j ] = bvp; - - bvp->bv_len = vlen; - if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) { - perror( "malloc" ); - exit( 1 ); - } - SAFEMEMCPY( bvp->bv_val, value, vlen ); - bvp->bv_val[ vlen ] = '\0'; - } -} - - -static char * -get_add_entry( char *filename, LDAPMod ***mods ) -{ - FILE *fp; - char *entry = NULL; - - if ( fp = fopen( filename, "r" )) { - char line[BUFSIZ]; - - if ( fgets( line, BUFSIZ, fp )) { - char *nl; - - if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) - *nl = '\0'; - entry = strdup( line ); - - } - - while ( fgets( line, BUFSIZ, fp )) { - char *nl; - char *value; - - if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) - *nl = '\0'; - - if ( *line == '\0' ) break; - if ( !( value = strchr( line, ':' ))) break; - - *value++ = '\0'; - while ( *value && isspace( *value )) value++; - - addmodifyop( mods, LDAP_MOD_ADD, line, value, strlen( value )); - - } - fclose( fp ); - } - - return( entry ); -} - - -static void -do_addel( - char *host, - int port, - char *manager, - char *passwd, - char *entry, - LDAPMod **attrs, - int maxloop -) -{ - LDAP *ld; - int i; - pid_t pid = getpid(); - - if (( ld = ldap_init( host, port )) == NULL ) { - perror( "ldap_init" ); - exit( 1 ); - } - - if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) - != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); - exit( 1 ); - } - - - fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n", - pid, maxloop, entry ); - - for ( i = 0; i < maxloop; i++ ) { - - /* add the entry */ - if ( ldap_add_s( ld, entry, attrs ) != LDAP_SUCCESS ) { - - ldap_perror( ld, "ldap_add" ); - break; - - } - - /* wait a second for the add to really complete */ - sleep( 1 ); - - /* now delete the entry again */ - if ( ldap_delete_s( ld, entry ) != LDAP_SUCCESS ) { - - ldap_perror( ld, "ldap_delete" ); - break; - - } - - } - - fprintf( stderr, " PID=%ld - Add/Delete done.\n", pid ); - - ldap_unbind( ld ); -} - - diff --git a/tests/slapd-read.c b/tests/slapd-read.c deleted file mode 100644 index b94ec3e705..0000000000 --- a/tests/slapd-read.c +++ /dev/null @@ -1,123 +0,0 @@ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include "lber.h" -#include "ldap.h" - -#define LOOPS 100 - -static void -do_read( char *host, int port, char *entry, int maxloop ); - -static void -usage( char *name ) -{ - fprintf( stderr, "usage: %s [-h ] -p port -e [-l ]\n", - name ); - exit( 1 ); -} - -int -main( int argc, char **argv ) -{ - int i, j; - char *host = "localhost"; - int port = -1; - char *entry = NULL; - int loops = LOOPS; - - while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) { - switch( i ) { - case 'h': /* the servers host */ - host = strdup( optarg ); - break; - - case 'p': /* the servers port */ - port = atoi( optarg ); - break; - - case 'e': /* file with entry search request */ - entry = strdup( optarg ); - break; - - case 'l': /* the number of loops */ - loops = atoi( optarg ); - break; - - default: - usage( argv[0] ); - break; - } - } - - if (( entry == NULL ) || ( port == -1 )) - usage( argv[0] ); - - if ( *entry == '\0' ) { - - fprintf( stderr, "%s: invalid EMPTY entry DN.\n", - argv[0] ); - exit( 1 ); - - } - - do_read( host, port, entry, ( 4 * loops )); - - exit( 0 ); -} - - -static void -do_read( char *host, int port, char *entry, int maxloop ) -{ - LDAP *ld; - int i; - char *attrs[] = { "cn", "sn", NULL }; - char *filter = "(objectclass=*)"; - pid_t pid = getpid(); - - if (( ld = ldap_init( host, port )) == NULL ) { - perror( "ldap_init" ); - exit( 1 ); - } - - if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); - exit( 1 ); - } - - - fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n", - pid, maxloop, entry ); - - for ( i = 0; i < maxloop; i++ ) { - LDAPMessage *res; - int rc; - - if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE, - filter, attrs, 0, &res )) != LDAP_SUCCESS ) { - - ldap_perror( ld, "ldap_read" ); - if ( rc != LDAP_NO_SUCH_OBJECT ) break; - continue; - - } - - ldap_msgfree( res ); - } - - fprintf( stderr, " PID=%ld - Read done.\n", pid ); - - ldap_unbind( ld ); -} - - diff --git a/tests/slapd-search.c b/tests/slapd-search.c deleted file mode 100644 index 27fc421be4..0000000000 --- a/tests/slapd-search.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include "lber.h" -#include "ldap.h" - -#define LOOPS 100 - -static void -do_search( char *host, int port, char *sbase, char *filter, int maxloop ); - -static void -usage( char *name ) -{ - fprintf( stderr, "usage: %s [-h ] -p port -b -f [-l ]\n", - name ); - exit( 1 ); -} - -int -main( int argc, char **argv ) -{ - int i, j; - char *host = "localhost"; - int port = -1; - char *sbase = NULL; - char *filter = NULL; - int loops = LOOPS; - - while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) { - switch( i ) { - case 'h': /* the servers host */ - host = strdup( optarg ); - break; - - case 'p': /* the servers port */ - port = atoi( optarg ); - break; - - case 'b': /* file with search base */ - sbase = strdup( optarg ); - break; - - case 'f': /* the search request */ - filter = strdup( optarg ); - break; - - case 'l': /* number of loops */ - loops = atoi( optarg ); - break; - - default: - usage( argv[0] ); - break; - } - } - - if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 )) - usage( argv[0] ); - - if ( *filter == '\0' ) { - - fprintf( stderr, "%s: invalid EMPTY search filter.\n", - argv[0] ); - exit( 1 ); - - } - - do_search( host, port, sbase, filter, ( 4 * loops )); - - exit( 0 ); -} - - -static void -do_search( char *host, int port, char *sbase, char *filter, int maxloop ) -{ - LDAP *ld; - int i; - char *attrs[] = { "cn", "sn", NULL }; - pid_t pid = getpid(); - - if (( ld = ldap_init( host, port )) == NULL ) { - perror( "ldap_init" ); - exit( 1 ); - } - - if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); - exit( 1 ); - } - - - fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n", - pid, maxloop, sbase, filter ); - - for ( i = 0; i < maxloop; i++ ) { - LDAPMessage *res; - int rc; - - if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, - filter, attrs, 0, &res )) != LDAP_SUCCESS ) { - - ldap_perror( ld, "ldap_search" ); - if ( rc != LDAP_NO_SUCH_OBJECT ) break; - continue; - - } - - ldap_msgfree( res ); - } - - fprintf( stderr, " PID=%ld - Search done.\n", pid ); - - ldap_unbind( ld ); -} - - diff --git a/tests/slapd-tester.c b/tests/slapd-tester.c deleted file mode 100644 index 5bf9d4ed20..0000000000 --- a/tests/slapd-tester.c +++ /dev/null @@ -1,352 +0,0 @@ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "ldapconfig.h" - - -#define SEARCHCMD "slapd-search" -#define READCMD "slapd-read" -#define ADDCMD "slapd-addel" -#define MAXARGS 100 -#define MAXREQS 20 -#define LOOPS "100" - -#define TSEARCHFILE "do_search.0" -#define TREADFILE "do_read.0" -#define TADDFILE "do_add." - -static char *get_file_name( char *dirname, char *filename ); -static int get_search_filters( char *filename, char *filters[] ); -static int get_read_entries( char *filename, char *entries[] ); -static void fork_child( char *prog, char *args[] ); -static void wait4kids( int nkidval ); - -static int maxkids = 20; -static int nkids; - -static void -usage( char *name ) -{ - fprintf( stderr, "usage: %s [-h ] -p -D -w -d -b [-j ] [-l ]\n", name ); - exit( 1 ); -} - -int -main( int argc, char **argv ) -{ - int i, j; - char *host = "localhost"; - char *port = NULL; - char *manager = NULL; - char *passwd = NULL; - char *dirname = NULL; - char *sbase = NULL; - char *loops = LOOPS; - DIR *datadir; - struct dirent *file; - char *sfile = NULL; - char *sreqs[MAXREQS]; - int snum = 0; - char *rfile = NULL; - char *rreqs[MAXREQS]; - int rnum = 0; - char *afiles[MAXREQS]; - int anum = 0; - char *sargs[MAXARGS]; - int sanum; - char scmd[MAXPATHLEN]; - char *rargs[MAXARGS]; - int ranum; - char rcmd[MAXPATHLEN]; - char *aargs[MAXARGS]; - int aanum; - char acmd[MAXPATHLEN]; - - while ( (i = getopt( argc, argv, "h:p:D:w:b:d:j:l:" )) != EOF ) { - switch( i ) { - case 'h': /* slapd host */ - host = strdup( optarg ); - break; - - case 'p': /* the servers port number */ - port = strdup( optarg ); - break; - - case 'D': /* slapd manager */ - manager = strdup( optarg ); - break; - - case 'w': /* the managers passwd */ - passwd = strdup( optarg ); - break; - - case 'b': /* the base DN */ - sbase = strdup( optarg ); - break; - - case 'd': /* data directory */ - dirname = strdup( optarg ); - break; - - case 'j': /* the number of parallel clients */ - maxkids = atoi( optarg ); - break; - - case 'l': /* the number of loops per client */ - loops = strdup( optarg ); - break; - - default: - usage( argv[0] ); - break; - } - } - - if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL ) || - ( manager == NULL ) || ( passwd == NULL )) - usage( argv[0] ); - - /* get the file list */ - if ( ( datadir = opendir( dirname )) == NULL ) { - - fprintf( stderr, "%s: couldn't open data directory \"%s\".\n", - argv[0], dirname ); - exit( 1 ); - - } - - /* look for search, read, and add/delete files */ - for ( file = readdir( datadir ); file; file = readdir( datadir )) { - - if ( !strcasecmp( file->d_name, TSEARCHFILE )) { - sfile = get_file_name( dirname, file->d_name ); - continue; - } else if ( !strcasecmp( file->d_name, TREADFILE )) { - rfile = get_file_name( dirname, file->d_name ); - continue; - } else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE )) - && ( anum < MAXREQS )) { - afiles[anum++] = get_file_name( dirname, file->d_name ); - continue; - } - } - - /* look for search requests */ - if ( sfile ) { - snum = get_search_filters( sfile, sreqs ); - } - - /* look for read requests */ - if ( rfile ) { - rnum = get_read_entries( rfile, rreqs ); - } - - /* - * generate the search clients - */ - - sanum = 0; - sprintf( scmd, "%s", SEARCHCMD ); - sargs[sanum++] = scmd; - sargs[sanum++] = "-h"; - sargs[sanum++] = host; - sargs[sanum++] = "-p"; - sargs[sanum++] = port; - sargs[sanum++] = "-b"; - sargs[sanum++] = sbase; - sargs[sanum++] = "-l"; - sargs[sanum++] = loops; - sargs[sanum++] = "-f"; - sargs[sanum++] = NULL; /* will hold the search request */ - sargs[sanum++] = NULL; - - /* - * generate the read clients - */ - - ranum = 0; - sprintf( rcmd, "%s", READCMD ); - rargs[ranum++] = rcmd; - rargs[ranum++] = "-h"; - rargs[ranum++] = host; - rargs[ranum++] = "-p"; - rargs[ranum++] = port; - rargs[ranum++] = "-l"; - rargs[ranum++] = loops; - rargs[ranum++] = "-e"; - rargs[ranum++] = NULL; /* will hold the read entry */ - rargs[ranum++] = NULL; - - /* - * generate the add/delete clients - */ - - aanum = 0; - sprintf( acmd, "%s", ADDCMD ); - aargs[aanum++] = acmd; - aargs[aanum++] = "-h"; - aargs[aanum++] = host; - aargs[aanum++] = "-p"; - aargs[aanum++] = port; - aargs[aanum++] = "-D"; - aargs[aanum++] = manager; - aargs[aanum++] = "-w"; - aargs[aanum++] = passwd; - aargs[aanum++] = "-l"; - aargs[aanum++] = loops; - aargs[aanum++] = "-f"; - aargs[aanum++] = NULL; /* will hold the add data file */ - aargs[aanum++] = NULL; - - for ( j = 0; j < MAXREQS; j++ ) { - - if ( j < snum ) { - - sargs[sanum - 2] = sreqs[j]; - fork_child( scmd, sargs ); - - } - - if ( j < rnum ) { - - rargs[ranum - 2] = rreqs[j]; - fork_child( rcmd, rargs ); - - } - - if ( j < anum ) { - - aargs[aanum - 2] = afiles[j]; - fork_child( acmd, aargs ); - - } - - } - - wait4kids( -1 ); - - exit( 0 ); -} - -static char * -get_file_name( char *dirname, char *filename ) -{ - char buf[MAXPATHLEN]; - - sprintf( buf, "%s%s%s", dirname, DEFAULT_DIRSEP, filename ); - return( strdup( buf )); -} - - -static int -get_search_filters( char *filename, char *filters[] ) -{ - FILE *fp; - int filter = 0; - - if ( fp = fopen( filename, "r" )) { - char line[BUFSIZ]; - - while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { - char *nl; - - if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) - *nl = '\0'; - filters[filter++] = strdup( line ); - - } - fclose( fp ); - } - - return( filter ); -} - - -static int -get_read_entries( char *filename, char *entries[] ) -{ - FILE *fp; - int entry = 0; - - if ( fp = fopen( filename, "r" )) { - char line[BUFSIZ]; - - while (( entry < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { - char *nl; - - if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) - *nl = '\0'; - entries[entry++] = strdup( line ); - - } - fclose( fp ); - } - - return( entry ); -} - - -static void -fork_child( char *prog, char *args[] ) -{ - int status, pid; - - wait4kids( maxkids ); - - switch ( pid = fork() ) { - case 0: /* child */ - execvp( prog, args ); - fprintf( stderr, "%s: ", prog ); - perror( "execv" ); - exit( -1 ); - break; - - case -1: /* trouble */ - fprintf( stderr, "Could not fork to run %s\n", prog ); - perror( "fork" ); - break; - - default: /* parent */ - nkids++; - break; - } -} - -static void -wait4kids( int nkidval ) -{ - int status; - unsigned char *p; - - while ( nkids >= nkidval ) { - wait( &status ); - p = (unsigned char *) &status; - if ( p[sizeof(int) - 1] == 0177 ) { - fprintf( stderr, - "stopping: child stopped with signal %d\n", - p[sizeof(int) - 2] ); - } else if ( p[sizeof(int) - 1] != 0 ) { - fprintf( stderr, - "stopping: child terminated with signal %d\n", - p[sizeof(int) - 1] ); - exit( p[sizeof(int) - 1] ); - } else if ( p[sizeof(int) - 2] != 0 ) { - fprintf( stderr, - "stopping: child exited with status %d\n", - p[sizeof(int) - 2] ); - exit( p[sizeof(int) - 2] ); - } else { - nkids--; - } - } -}