allow to pass timeout arg (tnx to Luca)

This commit is contained in:
Pierangelo Masarati 2005-08-19 07:27:32 +00:00
parent 59e8ac437b
commit dcf57de6b8
6 changed files with 134 additions and 45 deletions

View File

@ -41,12 +41,20 @@ get_add_entry( char *filename, LDAPMod ***mods );
static void
do_addel( char *uri, char *host, int port, char *manager, char *passwd,
char *dn, LDAPMod **attrs, int maxloop, int maxretries );
char *dn, LDAPMod **attrs, int maxloop, int maxretries, int delay );
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -f <addfile> [-l <loops>]\n",
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> "
"-w <passwd> "
"-f <addfile> "
"[-l <loops>] "
"[-r <maxretries>] "
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -64,9 +72,10 @@ main( int argc, char **argv )
char *entry = NULL;
int loops = LOOPS;
int retries = RETRIES;
int delay = 0;
LDAPMod **attrs = NULL;
while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:r:" )) != EOF ) {
while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:r:t:" )) != EOF ) {
switch( i ) {
case 'H': /* the server's URI */
uri = strdup( optarg );
@ -96,10 +105,14 @@ main( int argc, char **argv )
loops = atoi( optarg );
break;
case 'r':
case 'r': /* number of retries */
retries = atoi( optarg );
break;
case 't': /* delay in seconds */
delay = atoi( optarg );
break;
default:
usage( argv[0] );
break;
@ -128,7 +141,7 @@ main( int argc, char **argv )
}
do_addel( uri, host, port, manager, passwd, entry, attrs,
loops, retries );
loops, retries, delay );
exit( EXIT_SUCCESS );
}
@ -258,7 +271,8 @@ do_addel(
char *entry,
LDAPMod **attrs,
int maxloop,
int maxretries
int maxretries,
int delay
)
{
LDAP *ld = NULL;
@ -294,9 +308,11 @@ retry:;
switch ( rc ) {
case LDAP_BUSY:
case LDAP_UNAVAILABLE:
if ( do_retry == 1 ) {
do_retry = 0;
sleep( 1 );
if ( do_retry > 0 ) {
do_retry--;
if ( delay != 0 ) {
sleep( delay );
}
goto retry;
}
/* fallthru */

View File

@ -35,13 +35,21 @@
static void
do_modify( char *uri, char *host, int port, char *manager, char *passwd,
char *entry, char *attr, char *value, int maxloop,
int maxretries );
int maxretries, int delay );
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -e <entry> [-l <loops>]\n",
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> "
"-w <passwd> "
"-e <entry> "
"[-l <loops>] "
"[-r <maxretries>] "
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -60,8 +68,9 @@ main( int argc, char **argv )
char *value = NULL;
int loops = LOOPS;
int retries = RETRIES;
int delay = 0;
while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:r:" )) != EOF ) {
while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:r:t:" )) != EOF ) {
switch( i ) {
case 'H': /* the server uri */
uri = strdup( optarg );
@ -95,10 +104,14 @@ main( int argc, char **argv )
loops = atoi( optarg );
break;
case 'r':
case 'r': /* number of retries */
retries = atoi( optarg );
break;
case 't': /* delay in seconds */
delay = atoi( optarg );
break;
default:
usage( argv[0] );
break;
@ -131,7 +144,7 @@ main( int argc, char **argv )
value++;
do_modify( uri, host, port, manager, passwd, entry, ava, value,
loops, retries );
loops, retries, delay );
exit( EXIT_SUCCESS );
}
@ -139,7 +152,7 @@ main( int argc, char **argv )
static void
do_modify( char *uri, char *host, int port, char *manager,
char *passwd, char *entry, char* attr, char* value,
int maxloop, int maxretries )
int maxloop, int maxretries, int delay )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
@ -188,9 +201,11 @@ retry:;
switch ( rc ) {
case LDAP_BUSY:
case LDAP_UNAVAILABLE:
if ( do_retry == 1 ) {
do_retry = 0;
sleep( 1 );
if ( do_retry > 0 ) {
do_retry--;
if ( delay > 0 ) {
sleep( delay );
}
goto retry;
}
/* fallthru */

View File

@ -38,12 +38,20 @@
static void
do_modrdn( char *uri, char *host, int port, char *manager, char *passwd,
char *entry, int maxloop, int maxretries );
char *entry, int maxloop, int maxretries, int delay );
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -e <entry> [-l <loops>]\n",
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> "
"-w <passwd> "
"-e <entry> "
"[-l <loops>] "
"[-r <maxretries>] "
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -60,8 +68,9 @@ main( int argc, char **argv )
char *entry = NULL;
int loops = LOOPS;
int retries = RETRIES;
int delay = 0;
while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:r:" )) != EOF ) {
while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:r:t:" )) != EOF ) {
switch( i ) {
case 'H': /* the server uri */
uri = strdup( optarg );
@ -95,6 +104,10 @@ main( int argc, char **argv )
retries = atoi( optarg );
break;
case 't': /* delay in seconds */
delay = atoi( optarg );
break;
default:
usage( argv[0] );
break;
@ -112,14 +125,14 @@ main( int argc, char **argv )
}
do_modrdn( uri, host, port, manager, passwd, entry, loops, retries );
do_modrdn( uri, host, port, manager, passwd, entry, loops, retries, delay );
exit( EXIT_SUCCESS );
}
static void
do_modrdn( char *uri, char *host, int port, char *manager,
char *passwd, char *entry, int maxloop, int maxretries )
char *passwd, char *entry, int maxloop, int maxretries, int delay )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
@ -180,9 +193,11 @@ retry:;
switch ( rc ) {
case LDAP_BUSY:
case LDAP_UNAVAILABLE:
if ( do_retry == 1 ) {
do_retry = 0;
sleep( 1 );
if ( do_retry > 0 ) {
do_retry--;
if ( delay > 0) {
sleep( delay );
}
goto retry;
}
/* fallthru */

View File

@ -38,12 +38,18 @@
static void
do_read( char *uri, char *host, int port, char *entry, int maxloop,
int maxretries );
int maxretries, int delay );
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-e <entry> "
"[-l <loops>] "
"[-r <maxretries>] "
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -58,8 +64,9 @@ main( int argc, char **argv )
char *entry = NULL;
int loops = LOOPS;
int retries = RETRIES;
int delay = 0;
while ( (i = getopt( argc, argv, "H:h:p:e:l:r:" )) != EOF ) {
while ( (i = getopt( argc, argv, "H:h:p:e:l:r:t:" )) != EOF ) {
switch( i ) {
case 'H': /* the server uri */
uri = strdup( optarg );
@ -85,6 +92,10 @@ main( int argc, char **argv )
retries = atoi( optarg );
break;
case 't': /* delay in seconds */
delay = atoi( optarg );
break;
default:
usage( argv[0] );
break;
@ -100,14 +111,14 @@ main( int argc, char **argv )
exit( EXIT_FAILURE );
}
do_read( uri, host, port, entry, ( 20 * loops ), retries );
do_read( uri, host, port, entry, ( 20 * loops ), retries, delay );
exit( EXIT_SUCCESS );
}
static void
do_read( char *uri, char *host, int port, char *entry, int maxloop,
int maxretries )
int maxretries, int delay )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
@ -143,9 +154,11 @@ retry:;
switch ( rc ) {
case LDAP_BUSY:
case LDAP_UNAVAILABLE:
if ( do_retry == 1 ) {
do_retry = 0;
sleep( 1 );
if ( do_retry > 0 ) {
do_retry--;
if ( delay > 0 ) {
sleep( delay );
}
goto retry;
}
/* fallthru */

View File

@ -38,12 +38,21 @@
static void
do_search( char *uri, char *host, int port, char *manager, char *passwd,
char *sbase, char *filter, int maxloop, int maxretries );
char *sbase, char *filter, int maxloop, int maxretries, int delay );
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> "
"-w <passwd> "
"-b <searchbase> "
"-f <searchfilter> "
"[-l <loops>] "
"[-r <maxretries>] "
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -61,8 +70,9 @@ main( int argc, char **argv )
char *filter = NULL;
int loops = LOOPS;
int retries = RETRIES;
int delay = 0;
while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:" )) != EOF ) {
while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:t:" )) != EOF ) {
switch( i ) {
case 'H': /* the server uri */
uri = strdup( optarg );
@ -100,6 +110,10 @@ main( int argc, char **argv )
retries = atoi( optarg );
break;
case 't': /* delay in seconds */
delay = atoi( optarg );
break;
default:
usage( argv[0] );
break;
@ -118,14 +132,14 @@ main( int argc, char **argv )
}
do_search( uri, host, port, manager, passwd, sbase, filter,
( 10 * loops ), retries );
( 10 * loops ), retries, delay );
exit( EXIT_SUCCESS );
}
static void
do_search( char *uri, char *host, int port, char *manager, char *passwd,
char *sbase, char *filter, int maxloop, int maxretries )
char *sbase, char *filter, int maxloop, int maxretries, int delay )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
@ -163,7 +177,9 @@ retry:;
case LDAP_UNAVAILABLE:
if ( do_retry > 0 ) {
do_retry--;
sleep( 1 );
if ( delay != 0 ) {
sleep( delay );
}
goto retry;
}
/* fallthru */
@ -196,5 +212,3 @@ retry:;
ldap_unbind( ld );
}

View File

@ -80,7 +80,8 @@ usage( char *name )
"[-j <maxchild>] "
"[-l <loops>] "
"-P <progdir> "
"[-r <maxretries>]\n",
"[-r <maxretries>]"
"[-t <delay>]\n",
name );
exit( EXIT_FAILURE );
}
@ -98,6 +99,7 @@ main( int argc, char **argv )
char *progdir = NULL;
char *loops = LOOPS;
char *retries = RETRIES;
char *delay = "0";
DIR *datadir;
struct dirent *file;
char *sfile = NULL;
@ -132,7 +134,7 @@ main( int argc, char **argv )
char *moddn[MAXREQS];
int modnum = 0;
while ( (i = getopt( argc, argv, "D:d:H:h:j:l:P:p:r:w:" )) != EOF ) {
while ( (i = getopt( argc, argv, "D:d:H:h:j:l:P:p:r:t:w:" )) != EOF ) {
switch( i ) {
case 'D': /* slapd manager */
manager = ArgDup( optarg );
@ -166,10 +168,14 @@ main( int argc, char **argv )
port = strdup( optarg );
break;
case 'r':
case 'r': /* the number of retries in case of error */
retries = strdup( optarg );
break;
case 't': /* the delay in seconds between each retry */
delay = strdup( optarg );
break;
case 'w': /* the managers passwd */
passwd = ArgDup( optarg );
break;
@ -264,6 +270,8 @@ main( int argc, char **argv )
sargs[sanum++] = loops;
sargs[sanum++] = "-r";
sargs[sanum++] = retries;
sargs[sanum++] = "-t";
sargs[sanum++] = delay;
sargs[sanum++] = "-b";
sargs[sanum++] = NULL; /* will hold the search base */
sargs[sanum++] = "-f";
@ -291,6 +299,8 @@ main( int argc, char **argv )
rargs[ranum++] = loops;
rargs[ranum++] = "-r";
rargs[ranum++] = retries;
rargs[ranum++] = "-t";
rargs[ranum++] = delay;
rargs[ranum++] = "-e";
rargs[ranum++] = NULL; /* will hold the read entry */
rargs[ranum++] = NULL;
@ -320,6 +330,8 @@ main( int argc, char **argv )
margs[manum++] = loops;
margs[manum++] = "-r";
margs[manum++] = retries;
margs[manum++] = "-t";
margs[manum++] = delay;
margs[manum++] = "-e";
margs[manum++] = NULL; /* will hold the modrdn entry */
margs[manum++] = NULL;
@ -349,6 +361,8 @@ main( int argc, char **argv )
modargs[modanum++] = loops;
modargs[modanum++] = "-r";
modargs[modanum++] = retries;
modargs[modanum++] = "-t";
modargs[modanum++] = delay;
modargs[modanum++] = "-e";
modargs[modanum++] = NULL; /* will hold the modify entry */
modargs[modanum++] = "-a";;
@ -380,6 +394,8 @@ main( int argc, char **argv )
aargs[aanum++] = loops;
aargs[aanum++] = "-r";
aargs[aanum++] = retries;
aargs[aanum++] = "-t";
aargs[aanum++] = delay;
aargs[aanum++] = "-f";
aargs[aanum++] = NULL; /* will hold the add data file */
aargs[aanum++] = NULL;