1999-09-02 16:40:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-09-02 08:56:32 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-09-02 08:56:32 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-02-15 18:49:20 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
1999-03-29 09:40:17 +08:00
|
|
|
#include <ac/dirent.h>
|
1999-11-02 01:21:24 +08:00
|
|
|
#include <ac/param.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
#include <ac/socket.h>
|
1999-03-29 09:40:17 +08:00
|
|
|
#include <ac/string.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/wait.h>
|
|
|
|
|
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
#include "ldap_defaults.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define SEARCHCMD "slapd-search"
|
|
|
|
#define READCMD "slapd-read"
|
|
|
|
#define ADDCMD "slapd-addel"
|
2003-02-22 20:01:59 +08:00
|
|
|
#define MODRDNCMD "slapd-modrdn"
|
1999-02-15 18:49:20 +08:00
|
|
|
#define MAXARGS 100
|
|
|
|
#define MAXREQS 20
|
|
|
|
#define LOOPS "100"
|
|
|
|
|
|
|
|
#define TSEARCHFILE "do_search.0"
|
|
|
|
#define TREADFILE "do_read.0"
|
|
|
|
#define TADDFILE "do_add."
|
2003-02-22 20:01:59 +08:00
|
|
|
#define TMODRDNFILE "do_modrdn.0"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
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[] );
|
2002-07-26 21:29:37 +08:00
|
|
|
static void fork_child( char *prog, char **args );
|
1999-02-15 18:49:20 +08:00
|
|
|
static void wait4kids( int nkidval );
|
|
|
|
|
|
|
|
static int maxkids = 20;
|
|
|
|
static int nkids;
|
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifdef HAVE_WINSOCK
|
|
|
|
static HANDLE *children;
|
|
|
|
static char argbuf[BUFSIZ];
|
|
|
|
#define ArgDup(x) strdup(strcat(strcat(strcpy(argbuf,"\""),x),"\""))
|
|
|
|
#else
|
|
|
|
#define ArgDup(x) strdup(x)
|
|
|
|
#endif
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
static void
|
|
|
|
usage( char *name )
|
|
|
|
{
|
1999-02-22 19:28:01 +08:00
|
|
|
fprintf( stderr, "usage: %s [-h <host>] -p <port> -D <manager> -w <passwd> -d <datadir> -b <baseDN> [-j <maxchild>] [-l <loops>] -P <progdir>\n", name );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i, j;
|
2003-02-13 16:02:40 +08:00
|
|
|
char *uri = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *host = "localhost";
|
|
|
|
char *port = NULL;
|
|
|
|
char *manager = NULL;
|
|
|
|
char *passwd = NULL;
|
|
|
|
char *dirname = NULL;
|
|
|
|
char *sbase = NULL;
|
1999-02-22 19:28:01 +08:00
|
|
|
char *progdir = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
2003-02-22 20:01:59 +08:00
|
|
|
char *mfile = NULL;
|
|
|
|
char *mreqs[MAXREQS];
|
|
|
|
int mnum = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *sargs[MAXARGS];
|
|
|
|
int sanum;
|
|
|
|
char scmd[MAXPATHLEN];
|
|
|
|
char *rargs[MAXARGS];
|
|
|
|
int ranum;
|
|
|
|
char rcmd[MAXPATHLEN];
|
|
|
|
char *aargs[MAXARGS];
|
|
|
|
int aanum;
|
|
|
|
char acmd[MAXPATHLEN];
|
2003-02-22 20:01:59 +08:00
|
|
|
char *margs[MAXARGS];
|
|
|
|
int manum;
|
|
|
|
char mcmd[MAXPATHLEN];
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2003-02-13 16:02:40 +08:00
|
|
|
while ( (i = getopt( argc, argv, "H:h:p:D:w:b:d:j:l:P:" )) != EOF ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
switch( i ) {
|
2003-02-13 16:02:40 +08:00
|
|
|
case 'H': /* slapd uri */
|
|
|
|
uri = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
case 'h': /* slapd host */
|
|
|
|
host = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p': /* the servers port number */
|
|
|
|
port = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D': /* slapd manager */
|
2002-05-17 09:36:35 +08:00
|
|
|
manager = ArgDup( optarg );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w': /* the managers passwd */
|
2002-05-17 09:36:35 +08:00
|
|
|
passwd = ArgDup( optarg );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b': /* the base DN */
|
2002-05-17 09:36:35 +08:00
|
|
|
sbase = ArgDup( optarg );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* data directory */
|
|
|
|
dirname = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-02-22 19:28:01 +08:00
|
|
|
case 'P': /* prog directory */
|
|
|
|
progdir = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-13 16:02:40 +08:00
|
|
|
if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL && uri == NULL ) ||
|
1999-02-22 19:28:01 +08:00
|
|
|
( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL ))
|
1999-02-15 18:49:20 +08:00
|
|
|
usage( argv[0] );
|
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifdef HAVE_WINSOCK
|
|
|
|
children = malloc( maxkids * sizeof(HANDLE) );
|
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
/* get the file list */
|
|
|
|
if ( ( datadir = opendir( dirname )) == NULL ) {
|
|
|
|
|
|
|
|
fprintf( stderr, "%s: couldn't open data directory \"%s\".\n",
|
|
|
|
argv[0], dirname );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/* look for search, read, modrdn, and add/delete files */
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
2003-02-22 20:01:59 +08:00
|
|
|
} else if ( !strcasecmp( file->d_name, TMODRDNFILE )) {
|
|
|
|
mfile = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
1999-02-15 18:49:20 +08:00
|
|
|
} else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE ))
|
|
|
|
&& ( anum < MAXREQS )) {
|
|
|
|
afiles[anum++] = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-04 13:06:49 +08:00
|
|
|
closedir( datadir );
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/* look for search requests */
|
|
|
|
if ( sfile ) {
|
|
|
|
snum = get_search_filters( sfile, sreqs );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for read requests */
|
|
|
|
if ( rfile ) {
|
|
|
|
rnum = get_read_entries( rfile, rreqs );
|
|
|
|
}
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/* look for modrdn requests */
|
|
|
|
if ( mfile ) {
|
|
|
|
mnum = get_read_entries( mfile, mreqs );
|
|
|
|
}
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/*
|
|
|
|
* generate the search clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
sanum = 0;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( scmd, sizeof scmd, "%s" LDAP_DIRSEP SEARCHCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = scmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
sargs[sanum++] = "-H";
|
|
|
|
sargs[sanum++] = uri;
|
|
|
|
} else {
|
|
|
|
sargs[sanum++] = "-h";
|
|
|
|
sargs[sanum++] = host;
|
|
|
|
sargs[sanum++] = "-p";
|
|
|
|
sargs[sanum++] = port;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( rcmd, sizeof rcmd, "%s" LDAP_DIRSEP READCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = rcmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
rargs[ranum++] = "-H";
|
|
|
|
rargs[ranum++] = uri;
|
|
|
|
} else {
|
|
|
|
rargs[ranum++] = "-h";
|
|
|
|
rargs[ranum++] = host;
|
|
|
|
rargs[ranum++] = "-p";
|
|
|
|
rargs[ranum++] = port;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = "-l";
|
|
|
|
rargs[ranum++] = loops;
|
|
|
|
rargs[ranum++] = "-e";
|
|
|
|
rargs[ranum++] = NULL; /* will hold the read entry */
|
|
|
|
rargs[ranum++] = NULL;
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/*
|
|
|
|
* generate the modrdn clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
manum = 0;
|
|
|
|
snprintf( mcmd, sizeof mcmd, "%s" LDAP_DIRSEP MODRDNCMD,
|
|
|
|
progdir );
|
|
|
|
margs[manum++] = mcmd;
|
|
|
|
if ( uri ) {
|
|
|
|
margs[manum++] = "-H";
|
|
|
|
margs[manum++] = uri;
|
|
|
|
} else {
|
|
|
|
margs[manum++] = "-h";
|
|
|
|
margs[manum++] = host;
|
|
|
|
margs[manum++] = "-p";
|
|
|
|
margs[manum++] = port;
|
|
|
|
}
|
|
|
|
margs[manum++] = "-D";
|
|
|
|
margs[manum++] = manager;
|
|
|
|
margs[manum++] = "-w";
|
|
|
|
margs[manum++] = passwd;
|
|
|
|
margs[manum++] = "-l";
|
|
|
|
margs[manum++] = loops;
|
|
|
|
margs[manum++] = "-e";
|
|
|
|
margs[manum++] = NULL; /* will hold the modrdn entry */
|
|
|
|
margs[manum++] = NULL;
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/*
|
|
|
|
* generate the add/delete clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
aanum = 0;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( acmd, sizeof acmd, "%s" LDAP_DIRSEP ADDCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
aargs[aanum++] = acmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
aargs[aanum++] = "-H";
|
|
|
|
aargs[aanum++] = uri;
|
|
|
|
} else {
|
|
|
|
aargs[aanum++] = "-h";
|
|
|
|
aargs[aanum++] = host;
|
|
|
|
aargs[aanum++] = "-p";
|
|
|
|
aargs[aanum++] = port;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
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];
|
2002-05-17 09:44:02 +08:00
|
|
|
fork_child( scmd, sargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( j < rnum ) {
|
|
|
|
|
|
|
|
rargs[ranum - 2] = rreqs[j];
|
2002-05-17 09:44:02 +08:00
|
|
|
fork_child( rcmd, rargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
if ( j < mnum ) {
|
|
|
|
|
|
|
|
margs[manum - 2] = mreqs[j];
|
|
|
|
fork_child( mcmd, margs );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
if ( j < anum ) {
|
|
|
|
|
|
|
|
aargs[aanum - 2] = afiles[j];
|
2002-05-17 09:44:02 +08:00
|
|
|
fork_child( acmd, aargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wait4kids( -1 );
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_file_name( char *dirname, char *filename )
|
|
|
|
{
|
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( buf, sizeof buf, "%s" LDAP_DIRSEP "%s",
|
|
|
|
dirname, filename );
|
1999-02-15 18:49:20 +08:00
|
|
|
return( strdup( buf ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_search_filters( char *filename, char *filters[] )
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int filter = 0;
|
|
|
|
|
1999-03-04 21:22:06 +08:00
|
|
|
if ( (fp = fopen( filename, "r" )) != NULL ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
char line[BUFSIZ];
|
|
|
|
|
|
|
|
while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) {
|
|
|
|
char *nl;
|
|
|
|
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
2002-05-17 09:36:35 +08:00
|
|
|
filters[filter++] = ArgDup( line );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_read_entries( char *filename, char *entries[] )
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int entry = 0;
|
|
|
|
|
1999-03-04 21:22:06 +08:00
|
|
|
if ( (fp = fopen( filename, "r" )) != NULL ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
char line[BUFSIZ];
|
|
|
|
|
|
|
|
while (( entry < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) {
|
|
|
|
char *nl;
|
|
|
|
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
2002-05-17 09:36:35 +08:00
|
|
|
entries[entry++] = ArgDup( line );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( entry );
|
|
|
|
}
|
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifndef HAVE_WINSOCK
|
1999-02-15 18:49:20 +08:00
|
|
|
static void
|
2002-07-26 21:29:37 +08:00
|
|
|
fork_child( char *prog, char **args )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
1999-03-29 09:40:17 +08:00
|
|
|
pid_t pid;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
wait4kids( maxkids );
|
|
|
|
|
|
|
|
switch ( pid = fork() ) {
|
|
|
|
case 0: /* child */
|
2002-07-26 21:29:37 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
/* The __LIBASCII execvp only handles ASCII "prog",
|
|
|
|
* we still need to translate the arg vec ourselves.
|
|
|
|
*/
|
|
|
|
{ char *arg2[MAXREQS];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; args[i]; i++) {
|
|
|
|
arg2[i] = ArgDup(args[i]);
|
|
|
|
__atoe(arg2[i]);
|
|
|
|
}
|
|
|
|
arg2[i] = NULL;
|
|
|
|
args = arg2; }
|
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
execvp( prog, args );
|
|
|
|
fprintf( stderr, "%s: ", prog );
|
|
|
|
perror( "execv" );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
while ( nkids >= nkidval ) {
|
|
|
|
wait( &status );
|
1999-03-29 09:40:17 +08:00
|
|
|
|
|
|
|
if ( WIFSTOPPED(status) ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"stopping: child stopped with signal %d\n",
|
1999-03-29 09:40:17 +08:00
|
|
|
(int) WSTOPSIG(status) );
|
|
|
|
|
|
|
|
} else if ( WIFSIGNALED(status) ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
1999-03-29 09:40:17 +08:00
|
|
|
"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 ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"stopping: child exited with status %d\n",
|
1999-03-29 09:40:17 +08:00
|
|
|
(int) WEXITSTATUS(status) );
|
|
|
|
exit( WEXITSTATUS(status) );
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
} else {
|
|
|
|
nkids--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-17 09:36:35 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void
|
|
|
|
wait4kids( int nkidval )
|
|
|
|
{
|
|
|
|
int rc, i;
|
|
|
|
|
|
|
|
while ( nkids >= nkidval ) {
|
|
|
|
rc = WaitForMultipleObjects( nkids, children, FALSE, INFINITE );
|
|
|
|
for ( i=rc - WAIT_OBJECT_0; i<nkids-1; i++)
|
|
|
|
children[i] = children[i+1];
|
|
|
|
nkids--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-07-26 21:29:37 +08:00
|
|
|
fork_child( char *prog, char **args )
|
2002-05-17 09:36:35 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
wait4kids( maxkids );
|
|
|
|
|
|
|
|
rc = _spawnvp( _P_NOWAIT, prog, args );
|
|
|
|
|
|
|
|
if ( rc == -1 ) {
|
|
|
|
fprintf( stderr, "%s: ", prog );
|
|
|
|
perror("spawnvp");
|
|
|
|
} else {
|
|
|
|
children[nkids++] = (HANDLE)rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|