]> git.sur5r.net Git - openldap/commitdiff
add "retry" switch (currently needed to stress-test back-meta); defaults to old behavior
authorPierangelo Masarati <ando@openldap.org>
Wed, 20 Apr 2005 16:16:39 +0000 (16:16 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 20 Apr 2005 16:16:39 +0000 (16:16 +0000)
tests/progs/slapd-addel.c
tests/progs/slapd-modify.c
tests/progs/slapd-modrdn.c
tests/progs/slapd-read.c
tests/progs/slapd-search.c
tests/progs/slapd-tester.c

index 4b2377db56692a39d4b1e75cc81ed014b1cecb15..c96cdccd3528ba2db1f464dff1fba86f36ea58ea 100644 (file)
 #include <ldap.h>
 
 #define LOOPS  100
+#define RETRIES        0
 
 static char *
 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 );
+       char *dn, LDAPMod **attrs, int maxloop, int maxretries );
 
 static void
 usage( char *name )
@@ -54,48 +55,54 @@ int
 main( int argc, char **argv )
 {
        int             i;
-       char        *host = "localhost";
+       char            *host = "localhost";
        char            *uri = NULL;
-       int                     port = -1;
+       int             port = -1;
        char            *manager = NULL;
        char            *passwd = NULL;
        char            *filename = NULL;
        char            *entry = NULL;
-       int                     loops = LOOPS;
-       LDAPMod     **attrs = NULL;
+       int             loops = LOOPS;
+       int             retries = RETRIES;
+       LDAPMod         **attrs = NULL;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:r:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* the server's URI */
-                               uri = strdup( optarg );
+               case 'H':               /* the server's URI */
+                       uri = strdup( optarg );
                        break;
-                       case 'h':               /* the servers host */
-                               host = strdup( optarg );
+
+               case 'h':               /* the servers host */
+                       host = strdup( optarg );
                        break;
 
-                       case 'p':               /* the servers port */
-                               port = atoi( optarg );
-                               break;
+               case 'p':               /* the servers port */
+                       port = atoi( optarg );
+                       break;
 
-                       case 'D':               /* the servers manager */
-                               manager = strdup( optarg );
+               case 'D':               /* the servers manager */
+                       manager = strdup( optarg );
                        break;
 
-                       case 'w':               /* the server managers password */
-                               passwd = strdup( optarg );
+               case 'w':               /* the server managers password */
+                       passwd = strdup( optarg );
                        break;
 
-                       case 'f':               /* file with entry search request */
-                               filename = strdup( optarg );
-                               break;
+               case 'f':               /* file with entry search request */
+                       filename = strdup( optarg );
+                       break;
 
-                       case 'l':               /* the number of loops */
-                               loops = atoi( optarg );
-                               break;
+               case 'l':               /* the number of loops */
+                       loops = atoi( optarg );
+                       break;
 
-                       default:
-                               usage( argv[0] );
-                               break;
+               case 'r':
+                       retries = atoi( optarg );
+                       break;
+
+               default:
+                       usage( argv[0] );
+                       break;
                }
        }
 
@@ -120,7 +127,8 @@ main( int argc, char **argv )
 
        }
 
-       do_addel( uri, host, port, manager, passwd, entry, attrs, loops );
+       do_addel( uri, host, port, manager, passwd, entry, attrs,
+                       loops, retries );
 
        exit( EXIT_SUCCESS );
 }
@@ -249,14 +257,16 @@ do_addel(
        char *passwd,
        char *entry,
        LDAPMod **attrs,
-       int maxloop
+       int maxloop,
+       int maxretries
 )
 {
        LDAP    *ld = NULL;
-       int     i;
+       int     i = 0, do_retry = maxretries;
        pid_t   pid = getpid();
        int     rc = LDAP_SUCCESS;
 
+retry:;
        if ( uri ) {
                ldap_initialize( &ld, uri );
        } else {
@@ -273,22 +283,31 @@ do_addel(
                        &version ); 
        }
 
-       if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE )
-                               != LDAP_SUCCESS ) {
-               ldap_perror( ld, "ldap_bind" );
-                exit( EXIT_FAILURE );
+       if ( do_retry == maxretries ) {
+               fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
+                       (long) pid, maxloop, entry );
        }
 
+       rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE );
+       if ( rc != LDAP_SUCCESS ) {
+               ldap_perror( ld, "ldap_bind" );
+               if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                       do_retry--;
+                       goto retry;
+               }
+               exit( EXIT_FAILURE );
+       }
 
-       fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
-                                       (long) pid, maxloop, entry );
-
-       for ( i = 0; i < maxloop; i++ ) {
+       for ( ; i < maxloop; i++ ) {
 
                /* add the entry */
                rc = ldap_add_s( ld, entry, attrs );
                if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_add" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        break;
 
                }
@@ -303,10 +322,12 @@ do_addel(
                rc = ldap_delete_s( ld, entry );
                if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_delete" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        break;
-
                }
-
        }
 
        fprintf( stderr, " PID=%ld - Add/Delete done (%d).\n", (long) pid, rc );
index 847785947ab07194e16ebe1344a11a9244657b50..f9e9e58c176b1aaa6129589e375fb4674bd2a278 100644 (file)
 #include <ldap.h>
 
 #define LOOPS  100
+#define RETRIES 0
 
 static void
-do_modify( char *uri, char *host, int port, char *manager, char *passwd, char *entry, 
-               char *attr, char *value, int maxloop );
+do_modify( char *uri, char *host, int port, char *manager, char *passwd,
+               char *entry, char *attr, char *value, int maxloop,
+               int maxretries );
 
 
 static void
@@ -49,46 +51,56 @@ main( int argc, char **argv )
 {
        int             i;
        char            *uri = NULL;
-       char        *host = "localhost";
-       int                     port = -1;
+       char            *host = "localhost";
+       int             port = -1;
        char            *manager = NULL;
        char            *passwd = NULL;
        char            *entry = NULL;
        char            *ava = NULL;
        char            *value = NULL;
-       int                     loops = LOOPS;
+       int             loops = LOOPS;
+       int             retries = RETRIES;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:r:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* the server uri */
-                               uri = strdup( optarg );
+               case 'H':               /* the server uri */
+                       uri = strdup( optarg );
                        break;
-                       case 'h':               /* the servers host */
-                               host = strdup( optarg );
+
+               case 'h':               /* the servers host */
+                       host = strdup( optarg );
                        break;
 
-                       case 'p':               /* the servers port */
-                               port = atoi( optarg );
+               case 'p':               /* the servers port */
+                       port = atoi( optarg );
                        break;
-                       case 'D':               /* the servers manager */
-                               manager = strdup( optarg );
+
+               case 'D':               /* the servers manager */
+                       manager = strdup( optarg );
                        break;
 
-                       case 'w':               /* the server managers password */
-                               passwd = strdup( optarg );
+               case 'w':               /* the server managers password */
+                       passwd = strdup( optarg );
                        break;
-                       case 'e':               /* entry to modify */
-                               entry = strdup( optarg );
+
+               case 'e':               /* entry to modify */
+                       entry = strdup( optarg );
                        break;
-                       case 'a':
-                               ava = strdup( optarg );
+
+               case 'a':
+                       ava = strdup( optarg );
                        break;
-                       case 'l':               /* the number of loops */
-                               loops = atoi( optarg );
+
+               case 'l':               /* the number of loops */
+                       loops = atoi( optarg );
+                       break;
+
+               case 'r':
+                       retries = atoi( optarg );
                        break;
 
-                       default:
-                               usage( argv[0] );
+               default:
+                       usage( argv[0] );
                        break;
                }
        }
@@ -118,17 +130,19 @@ main( int argc, char **argv )
        while ( *value && isspace( (unsigned char) *value ))
                value++;
 
-       do_modify( uri, host, port, manager, passwd, entry, ava, value, loops );
+       do_modify( uri, host, port, manager, passwd, entry, ava, value,
+                       loops, retries );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
 do_modify( char *uri, char *host, int port, char *manager,
-       char *passwd, char *entry, char* attr, char* value, int maxloop )
+       char *passwd, char *entry, char* attr, char* value,
+       int maxloop, int maxretries )
 {
        LDAP    *ld = NULL;
-       int     i;
+       int     i = 0, do_retry = maxretries;
        pid_t   pid;
        int     rc = LDAP_SUCCESS;
 
@@ -144,7 +158,7 @@ do_modify( char *uri, char *host, int port, char *manager,
        mods[0] = &mod;
        mods[1] = NULL;
 
-       
+retry:;
        if ( uri ) {
                ldap_initialize( &ld, uri );
        } else {
@@ -161,26 +175,42 @@ do_modify( char *uri, char *host, int port, char *manager,
                        &version ); 
        }
 
-       if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
-               ldap_perror( ld, "ldap_bind" );
-                exit( EXIT_FAILURE );
+       if ( do_retry == maxretries ) {
+               fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n",
+                       (long) pid, maxloop, entry );
        }
 
-
-       fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n",
-                (long) pid, maxloop, entry );
+       rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE );
+       if ( rc != LDAP_SUCCESS ) {
+               ldap_perror( ld, "ldap_bind" );
+               if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                       do_retry--;
+                       goto retry;
+               }
+               exit( EXIT_FAILURE );
+       }
 
        for ( i = 0; i < maxloop; i++ ) {
                mod.mod_op = LDAP_MOD_ADD;
-               if (( rc = ldap_modify_s( ld, entry, mods )) != LDAP_SUCCESS ) {
+               rc = ldap_modify_s( ld, entry, mods );
+               if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_modify" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
                }
                
                mod.mod_op = LDAP_MOD_DELETE;
-               if (( rc = ldap_modify_s( ld, entry, mods )) != LDAP_SUCCESS ) {
+               rc = ldap_modify_s( ld, entry, mods );
+               if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_modify" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
                }
index 2ca60b4c0d5d0e9eddec6e52139fa00c1ec47ff8..37ba553b78d2d2c86fe698bb22d7e9479ea26b11 100644 (file)
 #include <ldap.h>
 
 #define LOOPS  100
+#define RETRIES        0
 
 static void
-do_modrdn( char *uri, char *host, int port, char *manager, char *passwd, char *entry, int maxloop );
+do_modrdn( char *uri, char *host, int port, char *manager, char *passwd,
+               char *entry, int maxloop, int maxretries );
 
 static void
 usage( char *name )
@@ -51,43 +53,51 @@ main( int argc, char **argv )
 {
        int             i;
        char            *uri = NULL;
-       char        *host = "localhost";
-       int                     port = -1;
+       char            *host = "localhost";
+       int             port = -1;
        char            *manager = NULL;
        char            *passwd = NULL;
        char            *entry = NULL;
-       int                     loops = LOOPS;
+       int             loops = LOOPS;
+       int             retries = RETRIES;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:r:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* the server uri */
-                               uri = strdup( optarg );
+               case 'H':               /* the server uri */
+                       uri = strdup( optarg );
                        break;
-                       case 'h':               /* the servers host */
-                               host = strdup( optarg );
+
+               case 'h':               /* the servers host */
+                       host = strdup( optarg );
                        break;
 
-                       case 'p':               /* the servers port */
-                               port = atoi( optarg );
-                               break;
-                       case 'D':               /* the servers manager */
-                               manager = strdup( optarg );
+               case 'p':               /* the servers port */
+                       port = atoi( optarg );
                        break;
 
-                       case 'w':               /* the server managers password */
-                               passwd = strdup( optarg );
+               case 'D':               /* the servers manager */
+                       manager = strdup( optarg );
                        break;
-                       case 'e':               /* entry to rename */
-                               entry = strdup( optarg );
-                               break;
 
-                       case 'l':               /* the number of loops */
-                               loops = atoi( optarg );
-                               break;
+               case 'w':               /* the server managers password */
+                       passwd = strdup( optarg );
+                       break;
 
-                       default:
-                               usage( argv[0] );
-                               break;
+               case 'e':               /* entry to rename */
+                       entry = strdup( optarg );
+                       break;
+
+               case 'l':               /* the number of loops */
+                       loops = atoi( optarg );
+                       break;
+
+               case 'r':               /* the number of retries */
+                       retries = atoi( optarg );
+                       break;
+
+               default:
+                       usage( argv[0] );
+                       break;
                }
        }
 
@@ -102,17 +112,17 @@ main( int argc, char **argv )
 
        }
 
-       do_modrdn( uri, host, port, manager, passwd, entry, loops );
+       do_modrdn( uri, host, port, manager, passwd, entry, loops, retries );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
 do_modrdn( char *uri, char *host, int port, char *manager,
-       char *passwd, char *entry, int maxloop )
+       char *passwd, char *entry, int maxloop, int maxretries )
 {
        LDAP    *ld = NULL;
-       int     i;
+       int     i = 0, do_retry = maxretries;
        pid_t   pid;
        char *DNs[2];
        char *rdns[2];
@@ -141,7 +151,8 @@ do_modrdn( char *uri, char *host, int port, char *manager,
                rdns[0] = strdup( DNs[1] );
                DNs[1][i] = ',';
        }
-               
+
+retry:;
        if ( uri ) {
                ldap_initialize( &ld, uri );
        } else {
@@ -158,25 +169,39 @@ do_modrdn( char *uri, char *host, int port, char *manager,
                        &version ); 
        }
 
-       if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
-               ldap_perror( ld, "ldap_bind" );
-                exit( EXIT_FAILURE );
+       if ( do_retry == maxretries ) {
+               fprintf( stderr, "PID=%ld - Modrdn(%d): entry=\"%s\".\n",
+                       (long) pid, maxloop, entry );
        }
 
-
-       fprintf( stderr, "PID=%ld - Modrdn(%d): entry=\"%s\".\n",
-                (long) pid, maxloop, entry );
+       rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE );
+       if ( rc != LDAP_SUCCESS ) {
+               ldap_perror( ld, "ldap_bind" );
+               if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                       do_retry--;
+                       goto retry;
+               }
+               exit( EXIT_FAILURE );
+       }
 
        for ( i = 0; i < maxloop; i++ ) {
-               if (( rc = ldap_modrdn2_s( ld, DNs[0], rdns[0], 0 ))
-                       != LDAP_SUCCESS ) {
+               rc = ldap_modrdn2_s( ld, DNs[0], rdns[0], 0 );
+               if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_modrdn" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
                }
-               if (( rc = ldap_modrdn2_s( ld, DNs[1], rdns[1], 1 ))
-                       != LDAP_SUCCESS ) {
+               rc = ldap_modrdn2_s( ld, DNs[1], rdns[1], 1 );
+               if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_modrdn" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
                }
index bcc24a23810af417f91311f51b2275a97898bba0..c3c09758b5e6057e03adf611fc2d0b002f1f30a1 100644 (file)
 #include <ldap.h>
 
 #define LOOPS  100
+#define RETRIES        0
 
 static void
-do_read( char *uri, char *host, int port, char *entry, int maxloop );
+do_read( char *uri, char *host, int port, char *entry, int maxloop,
+               int maxretries );
 
 static void
 usage( char *name )
@@ -51,35 +53,41 @@ main( int argc, char **argv )
 {
        int             i;
        char            *uri = NULL;
-       char        *host = "localhost";
-       int                     port = -1;
+       char            *host = "localhost";
+       int             port = -1;
        char            *entry = NULL;
-       int                     loops = LOOPS;
+       int             loops = LOOPS;
+       int             retries = RETRIES;
 
-       while ( (i = getopt( argc, argv, "H:h:p:e:l:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:e:l:r:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* the server uri */
-                               uri = strdup( optarg );
+               case 'H':               /* the server uri */
+                       uri = strdup( optarg );
                        break;
-                       case 'h':               /* the servers host */
-                               host = strdup( optarg );
+
+               case 'h':               /* the servers host */
+                       host = strdup( optarg );
                        break;
 
-                       case 'p':               /* the servers port */
-                               port = atoi( optarg );
-                               break;
+               case 'p':               /* the servers port */
+                       port = atoi( optarg );
+                       break;
 
-                       case 'e':               /* file with entry search request */
-                               entry = strdup( optarg );
-                               break;
+               case 'e':               /* DN to search for */
+                       entry = strdup( optarg );
+                       break;
 
-                       case 'l':               /* the number of loops */
-                               loops = atoi( optarg );
-                               break;
+               case 'l':               /* the number of loops */
+                       loops = atoi( optarg );
+                       break;
 
-                       default:
-                               usage( argv[0] );
-                               break;
+               case 'r':               /* the number of retries */
+                       retries = atoi( optarg );
+                       break;
+
+               default:
+                       usage( argv[0] );
+                       break;
                }
        }
 
@@ -87,27 +95,27 @@ main( int argc, char **argv )
                usage( argv[0] );
 
        if ( *entry == '\0' ) {
-
                fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
                                argv[0] );
                exit( EXIT_FAILURE );
-
        }
 
-       do_read( uri, host, port, entry, ( 20 * loops ));
+       do_read( uri, host, port, entry, ( 20 * loops ), retries );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
-do_read( char *uri, char *host, int port, char *entry, int maxloop )
+do_read( char *uri, char *host, int port, char *entry, int maxloop,
+               int maxretries )
 {
        LDAP    *ld = NULL;
-       int     i;
+       int     i = 0, do_retry = maxretries;
        char    *attrs[] = { "1.1", NULL };
        pid_t   pid = getpid();
        int     rc = LDAP_SUCCESS;
-
+       
+retry:;
        if ( uri ) {
                ldap_initialize( &ld, uri );
        } else {
@@ -124,22 +132,32 @@ do_read( char *uri, char *host, int port, char *entry, int maxloop )
                        &version ); 
        }
 
-       if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
-               ldap_perror( ld, "ldap_bind" );
-                exit( EXIT_FAILURE );
+       if ( do_retry == maxretries ) {
+               fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
+                       (long) pid, maxloop, entry );
        }
 
+       rc = ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE );
+       if ( rc != LDAP_SUCCESS ) {
+               ldap_perror( ld, "ldap_bind" );
+               if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                       do_retry--;
+                       goto retry;
+               }
+               exit( EXIT_FAILURE );
+       }
 
-       fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
-                (long) pid, maxloop, entry );
-
-       for ( i = 0; i < maxloop; i++ ) {
+       for ( ; i < maxloop; i++ ) {
                LDAPMessage *res;
 
                rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
                                NULL, attrs, 1, &res );
                if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_read" );
+                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                               do_retry--;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
 
@@ -153,4 +171,3 @@ do_read( char *uri, char *host, int port, char *entry, int maxloop )
        ldap_unbind( ld );
 }
 
-
index 790b20dea676bb9e7b9996b2874b1171a07b089c..dfd97ad2299eae1b28aa30847612a7710a7451d8 100644 (file)
 #include <ldap.h>
 
 #define LOOPS  100
+#define RETRIES        0
 
 static void
-do_search( char *uri, char *host, int port, char *manager, char *passwd, char *sbase, char *filter, int maxloop );
+do_search( char *uri, char *host, int port, char *manager, char *passwd,
+               char *sbase, char *filter, int maxloop, int maxretries );
 
 static void
 usage( char *name )
@@ -51,50 +53,56 @@ main( int argc, char **argv )
 {
        int             i;
        char            *uri = NULL;
-       char        *host = "localhost";
-       int                     port = -1;
+       char            *host = "localhost";
+       int             port = -1;
        char            *manager = NULL;
        char            *passwd = NULL;
-       char        *sbase = NULL;
+       char            *sbase = NULL;
        char            *filter  = NULL;
-       int                     loops = LOOPS;
+       int             loops = LOOPS;
+       int             retries = RETRIES;
 
-       while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* the server uri */
-                               uri = strdup( optarg );
+               case 'H':               /* the server uri */
+                       uri = strdup( optarg );
                        break;
-                       case 'h':               /* the servers host */
-                               host = strdup( optarg );
+
+               case 'h':               /* the servers host */
+                       host = strdup( optarg );
+                       break;
+
+               case 'p':               /* the servers port */
+                       port = atoi( optarg );
                        break;
 
-                       case 'p':               /* the servers port */
-                               port = atoi( optarg );
-                               break;
+               case 'D':               /* the servers manager */
+                       manager = strdup( optarg );
+                       break;
 
-                       case 'D':               /* the servers manager */
-                               manager = strdup( optarg );
+               case 'w':               /* the server managers password */
+                       passwd = strdup( optarg );
                        break;
 
-                       case 'w':               /* the server managers password */
-                               passwd = strdup( optarg );
+               case 'b':               /* file with search base */
+                       sbase = strdup( optarg );
                        break;
 
-                       case 'b':               /* file with search base */
-                               sbase = strdup( optarg );
+               case 'f':               /* the search request */
+                       filter = strdup( optarg );
                        break;
 
-                       case 'f':               /* the search request */
-                               filter = strdup( optarg );
-                               break;
+               case 'l':               /* number of loops */
+                       loops = atoi( optarg );
+                       break;
 
-                       case 'l':               /* number of loops */
-                               loops = atoi( optarg );
-                               break;
+               case 'r':               /* number of retries */
+                       retries = atoi( optarg );
+                       break;
 
-                       default:
-                               usage( argv[0] );
-                               break;
+               default:
+                       usage( argv[0] );
+                       break;
                }
        }
 
@@ -109,20 +117,23 @@ main( int argc, char **argv )
 
        }
 
-       do_search( uri, host, port, manager, passwd, sbase, filter, ( 10 * loops ));
+       do_search( uri, host, port, manager, passwd, sbase, filter,
+                       ( 10 * loops ), retries );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
-do_search( char *uri, char *host, int port, char *manager, char *passwd, char *sbase, char *filter, int maxloop )
+do_search( char *uri, char *host, int port, char *manager, char *passwd,
+               char *sbase, char *filter, int maxloop, int maxretries )
 {
        LDAP    *ld = NULL;
-       int     i;
+       int     i = 0, do_retry = maxretries;
        char    *attrs[] = { "cn", "sn", NULL };
        pid_t   pid = getpid();
        int     rc = LDAP_SUCCESS;
 
+retry:;
        if ( uri ) {
                ldap_initialize( &ld, uri );
        } else {
@@ -139,14 +150,20 @@ do_search( char *uri, char *host, int port, char *manager, char *passwd, char *s
                        &version ); 
        }
 
-       if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
-               ldap_perror( ld, "ldap_bind" );
-                exit( EXIT_FAILURE );
+       if ( do_retry == maxretries ) {
+               fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
+                               (long) pid, maxloop, sbase, filter );
        }
 
-
-       fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
-                               (long) pid, maxloop, sbase, filter );
+       rc = ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE );
+       if ( rc != LDAP_SUCCESS ) {
+               if ( rc == LDAP_BUSY && do_retry == 1 ) {
+                       do_retry = 0;
+                       goto retry;
+               }
+               ldap_perror( ld, "ldap_bind" );
+               exit( EXIT_FAILURE );
+       }
 
        for ( i = 0; i < maxloop; i++ ) {
                LDAPMessage *res;
@@ -155,6 +172,10 @@ do_search( char *uri, char *host, int port, char *manager, char *passwd, char *s
                                filter, attrs, 0, &res );
                if ( rc != LDAP_SUCCESS ) {
                        ldap_perror( ld, "ldap_search" );
+                       if ( rc == LDAP_BUSY && do_retry == 1 ) {
+                               do_retry = 0;
+                               goto retry;
+                       }
                        if ( rc != LDAP_NO_SUCH_OBJECT ) break;
                        continue;
 
index 2d3819870a63731e4b6d91638dcbb55b42bc9699..7d14de72c6f7eab833bffa36eff9b66e2d569a72 100644 (file)
@@ -43,6 +43,7 @@
 #define MAXARGS                100
 #define MAXREQS                        5000
 #define LOOPS                  "100"
+#define RETRIES                        "0"
 
 #define TSEARCHFILE            "do_search.0"
 #define TREADFILE              "do_read.0"
@@ -86,6 +87,7 @@ main( int argc, char **argv )
        char            *dirname = NULL;
        char            *progdir = NULL;
        char            *loops = LOOPS;
+       char            *retries = RETRIES;
        DIR                     *datadir;
        struct dirent   *file;
        char            *sfile = NULL;
@@ -120,47 +122,51 @@ main( int argc, char **argv )
        char            *moddn[MAXREQS];
        int             modnum = 0;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:b:d:j:l:P:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "D:d:H:h:j:l:P:p:r:w:" )) != EOF ) {
                switch( i ) {
-                       case 'H':               /* slapd uri */
-                               uri = strdup( optarg );
+               case 'D':               /* slapd manager */
+                       manager = ArgDup( optarg );
                        break;
-                               
-                       case 'h':               /* slapd host */
-                               host = strdup( optarg );
+
+               case 'd':               /* data directory */
+                       dirname = strdup( optarg );
+                       break;
+
+               case 'H':               /* slapd uri */
+                       uri = strdup( optarg );
                        break;
 
-                       case 'p':               /* the servers port number */
-                               port = strdup( optarg );
-                               break;
+               case 'h':               /* slapd host */
+                       host = strdup( optarg );
+                       break;
 
-                       case 'D':               /* slapd manager */
-                               manager = ArgDup( optarg );
+               case 'j':               /* the number of parallel clients */
+                       maxkids = atoi( optarg );
                        break;
 
-                       case 'w':               /* the managers passwd */
-                               passwd = ArgDup( optarg );
-                               break;
+               case 'l':               /* the number of loops per client */
+                       loops = strdup( optarg );
+                       break;
 
-                       case 'd':               /* data directory */
-                               dirname = strdup( optarg );
+               case 'P':               /* prog directory */
+                       progdir = strdup( optarg );
                        break;
 
-                       case 'P':               /* prog directory */
-                               progdir = strdup( optarg );
+               case 'p':               /* the servers port number */
+                       port = strdup( optarg );
                        break;
 
-                       case 'j':               /* the number of parallel clients */
-                               maxkids = atoi( optarg );
-                               break;
+               case 'r':
+                       retries = strdup( optarg );
+                       break;
 
-                       case 'l':               /* the number of loops per client */
-                               loops = strdup( optarg );
-                               break;
+               case 'w':               /* the managers passwd */
+                       passwd = ArgDup( optarg );
+                       break;
 
-                       default:
-                               usage( argv[0] );
-                               break;
+               default:
+                       usage( argv[0] );
+                       break;
                }
        }
 
@@ -246,6 +252,8 @@ main( int argc, char **argv )
        sargs[sanum++] = passwd;
        sargs[sanum++] = "-l";
        sargs[sanum++] = loops;
+       sargs[sanum++] = "-r";
+       sargs[sanum++] = retries;
        sargs[sanum++] = "-b";
        sargs[sanum++] = NULL;          /* will hold the search base */
        sargs[sanum++] = "-f";
@@ -271,6 +279,8 @@ main( int argc, char **argv )
        }
        rargs[ranum++] = "-l";
        rargs[ranum++] = loops;
+       rargs[ranum++] = "-r";
+       rargs[ranum++] = retries;
        rargs[ranum++] = "-e";
        rargs[ranum++] = NULL;          /* will hold the read entry */
        rargs[ranum++] = NULL;
@@ -298,6 +308,8 @@ main( int argc, char **argv )
        margs[manum++] = passwd;
        margs[manum++] = "-l";
        margs[manum++] = loops;
+       margs[manum++] = "-r";
+       margs[manum++] = retries;
        margs[manum++] = "-e";
        margs[manum++] = NULL;          /* will hold the modrdn entry */
        margs[manum++] = NULL;
@@ -325,6 +337,8 @@ main( int argc, char **argv )
        modargs[modanum++] = passwd;
        modargs[modanum++] = "-l";
        modargs[modanum++] = loops;
+       modargs[modanum++] = "-r";
+       modargs[modanum++] = retries;
        modargs[modanum++] = "-e";
        modargs[modanum++] = NULL;              /* will hold the modify entry */
        modargs[modanum++] = "-a";;
@@ -354,6 +368,8 @@ main( int argc, char **argv )
        aargs[aanum++] = passwd;
        aargs[aanum++] = "-l";
        aargs[aanum++] = loops;
+       aargs[aanum++] = "-r";
+       aargs[aanum++] = retries;
        aargs[aanum++] = "-f";
        aargs[aanum++] = NULL;          /* will hold the add data file */
        aargs[aanum++] = NULL;