]> git.sur5r.net Git - openldap/blobdiff - tests/progs/slapd-tester.c
Delete CDB (no transactions) support
[openldap] / tests / progs / slapd-tester.c
index 51f8bee1701e1d152156842f4dd532386ad63c73..e925feff59827d6b05e2205d00d85dc097bc9390 100644 (file)
@@ -1,18 +1,24 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
 
-#include <ac/string.h>
+#include <ac/stdlib.h>
+
 #include <ac/ctype.h>
+#include <ac/dirent.h>
+#include <ac/param.h>
 #include <ac/socket.h>
+#include <ac/string.h>
 #include <ac/unistd.h>
 #include <ac/wait.h>
-#include <dirent.h>
 
-#include <sys/param.h>
 
-#include "ldapconfig.h"
+#include "ldap_defaults.h"
 
 
 #define SEARCHCMD              "slapd-search"
@@ -39,7 +45,7 @@ static void
 usage( char *name )
 {
        fprintf( stderr, "usage: %s [-h <host>] -p <port> -D <manager> -w <passwd> -d <datadir> -b <baseDN> [-j <maxchild>] [-l <loops>] -P <progdir>\n", name );
-       exit( 1 );
+       exit( EXIT_FAILURE );
 }
 
 int
@@ -127,7 +133,7 @@ main( int argc, char **argv )
 
                fprintf( stderr, "%s: couldn't open data directory \"%s\".\n",
                                        argv[0], dirname );
-               exit( 1 );
+               exit( EXIT_FAILURE );
 
        }
 
@@ -147,6 +153,8 @@ main( int argc, char **argv )
                }
        }
 
+       closedir( datadir );
+
        /* look for search requests */
        if ( sfile ) {
                snum = get_search_filters( sfile, sreqs );
@@ -162,7 +170,7 @@ main( int argc, char **argv )
         */
 
        sanum = 0;
-       sprintf( scmd, "%s%s%s", progdir, DEFAULT_DIRSEP, SEARCHCMD );
+       sprintf( scmd, "%s%s%s", progdir, LDAP_DIRSEP, SEARCHCMD );
        sargs[sanum++] = scmd;
        sargs[sanum++] = "-h";
        sargs[sanum++] = host;
@@ -181,7 +189,7 @@ main( int argc, char **argv )
         */
 
        ranum = 0;
-       sprintf( rcmd, "%s%s%s", progdir, DEFAULT_DIRSEP, READCMD );
+       sprintf( rcmd, "%s%s%s", progdir, LDAP_DIRSEP, READCMD );
        rargs[ranum++] = rcmd;
        rargs[ranum++] = "-h";
        rargs[ranum++] = host;
@@ -198,7 +206,7 @@ main( int argc, char **argv )
         */
 
        aanum = 0;
-       sprintf( acmd, "%s%s%s", progdir, DEFAULT_DIRSEP, ADDCMD );
+       sprintf( acmd, "%s%s%s", progdir, LDAP_DIRSEP, ADDCMD );
        aargs[aanum++] = acmd;
        aargs[aanum++] = "-h";
        aargs[aanum++] = host;
@@ -241,7 +249,7 @@ main( int argc, char **argv )
 
        wait4kids( -1 );
 
-       exit( 0 );
+       exit( EXIT_SUCCESS );
 }
 
 static char *
@@ -249,7 +257,7 @@ get_file_name( char *dirname, char *filename )
 {
        char buf[MAXPATHLEN];
 
-       sprintf( buf, "%s%s%s", dirname, DEFAULT_DIRSEP, filename );
+       sprintf( buf, "%s%s%s", dirname, LDAP_DIRSEP, filename );
        return( strdup( buf ));
 }
 
@@ -305,7 +313,7 @@ get_read_entries( char *filename, char *entries[] )
 static void
 fork_child( char *prog, char *args[] )
 {
-       int     pid;
+       pid_t   pid;
 
        wait4kids( maxkids );
 
@@ -314,7 +322,7 @@ fork_child( char *prog, char *args[] )
                execvp( prog, args );
                fprintf( stderr, "%s: ", prog );
                perror( "execv" );
-               exit( -1 );
+               exit( EXIT_FAILURE );
                break;
 
        case -1:        /* trouble */
@@ -332,25 +340,33 @@ 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 ) {
+
+               if ( WIFSTOPPED(status) ) {
                        fprintf( stderr,
                            "stopping: child stopped with signal %d\n",
-                           p[sizeof(int) - 2] );
-               } else if ( p[sizeof(int) - 1] != 0 ) {
+                           (int) WSTOPSIG(status) );
+
+               } else if ( WIFSIGNALED(status) ) {
                        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 ) {
+                           "stopping: child terminated with signal %d%s\n",
+                           (int) WTERMSIG(status),
+#ifdef WCOREDUMP
+                               WCOREDUMP(status) ? ", core dumped" : ""
+#else
+                               ""
+#endif
+                               );
+                       exit( WEXITSTATUS(status)  );
+
+               } else if ( WEXITSTATUS(status) != 0 ) {
                        fprintf( stderr, 
                            "stopping: child exited with status %d\n",
-                           p[sizeof(int) - 2] );
-                       exit( p[sizeof(int) - 2] );
+                           (int) WEXITSTATUS(status) );
+                       exit( WEXITSTATUS(status) );
+
                } else {
                        nkids--;
                }