From: Pierangelo Masarati Date: Fri, 19 Aug 2005 07:27:32 +0000 (+0000) Subject: allow to pass timeout arg (tnx to Luca) X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~656 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dcf57de6b85262892cb48296ef9d0214921cde39;p=openldap allow to pass timeout arg (tnx to Luca) --- diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index 6b8caacc06..082a7aa3d5 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -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 ] -p port -D -w -f [-l ]\n", + fprintf( stderr, + "usage: %s " + "-H | ([-h ] -p ) " + "-D " + "-w " + "-f " + "[-l ] " + "[-r ] " + "[-t ]\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 */ diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c index b639df5539..c0484dbc5c 100644 --- a/tests/progs/slapd-modify.c +++ b/tests/progs/slapd-modify.c @@ -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 ] -p port -D -w -e [-l ]\n", + fprintf( stderr, + "usage: %s " + "-H | ([-h ] -p ) " + "-D " + "-w " + "-e " + "[-l ] " + "[-r ] " + "[-t ]\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 */ diff --git a/tests/progs/slapd-modrdn.c b/tests/progs/slapd-modrdn.c index 2e95ddfa03..06b5130442 100644 --- a/tests/progs/slapd-modrdn.c +++ b/tests/progs/slapd-modrdn.c @@ -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 ] -p port -D -w -e [-l ]\n", + fprintf( stderr, + "usage: %s " + "-H | ([-h ] -p ) " + "-D " + "-w " + "-e " + "[-l ] " + "[-r ] " + "[-t ]\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 */ diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index e2c0768679..c5cb56ce33 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -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 ] -p port -e [-l ]\n", + fprintf( stderr, + "usage: %s " + "-H | ([-h ] -p ) " + "-e " + "[-l ] " + "[-r ] " + "[-t ]\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 */ diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 7158831056..9d9afe1e4f 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -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 ] -p port -b -f [-l ]\n", + fprintf( stderr, + "usage: %s " + "-H | ([-h ] -p ) " + "-D " + "-w " + "-b " + "-f " + "[-l ] " + "[-r ] " + "[-t ]\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 ); } - - diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 4121b4d174..c8d4d57f25 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -80,7 +80,8 @@ usage( char *name ) "[-j ] " "[-l ] " "-P " - "[-r ]\n", + "[-r ]" + "[-t ]\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;