+/* $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"
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
fprintf( stderr, "%s: couldn't open data directory \"%s\".\n",
argv[0], dirname );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
}
}
+ closedir( datadir );
+
/* look for search requests */
if ( sfile ) {
snum = get_search_filters( sfile, sreqs );
*/
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;
*/
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;
*/
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;
wait4kids( -1 );
- exit( 0 );
+ exit( EXIT_SUCCESS );
}
static char *
{
char buf[MAXPATHLEN];
- sprintf( buf, "%s%s%s", dirname, DEFAULT_DIRSEP, filename );
+ sprintf( buf, "%s%s%s", dirname, LDAP_DIRSEP, filename );
return( strdup( buf ));
}
static void
fork_child( char *prog, char *args[] )
{
- int pid;
+ pid_t pid;
wait4kids( maxkids );
execvp( prog, args );
fprintf( stderr, "%s: ", prog );
perror( "execv" );
- exit( -1 );
+ exit( EXIT_FAILURE );
break;
case -1: /* trouble */
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--;
}