Jelajahi Sumber

Resolves: #250347
Summary: rsearch - make search timeout a configurable parameter
Description: Introduced a new option "-o <search time limit>"

Noriko Hosoi 18 tahun lalu
induk
melakukan
2ebeaf1fbb

+ 8 - 2
ldap/servers/slapd/tools/rsearch/rsearch.c

@@ -96,6 +96,7 @@ void usage()
 	   "-a file   -- list of attributes for search request in a file\n" 
 	   "          -- (use '-a \\?' to see the format ; -a & -A are mutually exclusive)\n"
 	   "-n number -- (reserved for future use)\n"
+	   "-o number -- Search time limit, in seconds; (default: 30; no time limit: 0)\n"
 	   "-j number -- sample interval, in seconds  (default: %u)\n"
 	   "-t number -- threads  (default: %d)\n"
 	   "-T number -- Time limit, in seconds; cmd stops when exceeds <number>\n"
@@ -202,6 +203,7 @@ char **string_to_list(char* s)
 char *hostname = DEFAULT_HOSTNAME;
 int port = DEFAULT_PORT;
 int numeric = 0;
+int searchTimelimit = 30;
 int threadCount = DEFAULT_THREADS;
 int verbose = 0;
 int logging = 0;
@@ -251,7 +253,7 @@ int main(int argc, char** argv)
     }
 
     while ((ch = getopt(argc, argv, 
-			"B:a:j:i:h:s:f:p:t:T:D:w:n:A:S:C:R:bvlyqmMcduNLHx?V"))
+			"B:a:j:i:h:s:f:p:o:t:T:D:w:n:A:S:C:R:bvlyqmMcduNLHx?V"))
 	   != EOF)
 	switch (ch) {
 	case 'h':
@@ -308,6 +310,9 @@ int main(int argc, char** argv)
 	case 'n':			
 	    numeric = atoi(optarg);
 	    break;
+	case 'o':		
+	    searchTimelimit = atoi(optarg);
+	    break;
 	case 't':		
 	    threadCount = atoi(optarg);
 	    break;
@@ -447,11 +452,12 @@ int main(int argc, char** argv)
 	for (x = 0; x < numThreads; x++) {
 	    alive = st_alive(threads[x]);
 	    if (alive < 1) {
+		int limit = -1 * (searchTimelimit>timeLimit?searchTimelimit:timeLimit + 40) * 1000 / sampleInterval;
 		int y;
 		PRThread *tid;
 
 		printf("T%d no heartbeat", st_getThread(threads[x], &tid));
-		if (alive <= -4) {
+		if (alive <= limit) {
 		    printf(" -- Dead thread being reaped.\n");
 		    PR_JoinThread(tid);
 		    for (y = x+1; y < numThreads; y++)

+ 1 - 0
ldap/servers/slapd/tools/rsearch/rsearch.h

@@ -52,6 +52,7 @@ typedef enum { op_search, op_modify, op_idxmodify, op_add, op_delete, op_compare
 extern char *hostname;
 extern int port;
 extern int numeric;
+extern int searchTimelimit;
 /**/ extern int threadCount;
 /**/ extern int verbose;
 /**/ extern int logging;

+ 9 - 3
ldap/servers/slapd/tools/rsearch/searchthread.c

@@ -285,6 +285,7 @@ static int st_search(SearchThread *st)
     char filterBuffer[100];
     char *pFilter;
     struct timeval timeout;
+    struct timeval *timeoutp;
     int scope, attrsOnly = 0;
     LDAPMessage *result;
     int ret;
@@ -312,10 +313,15 @@ static int st_search(SearchThread *st)
     if (!attrToReturn)
         attrToReturn = nt_get_all(attrTable);
 
-    timeout.tv_sec = 30;
-    timeout.tv_usec = 0;
+    if (searchTimelimit <= 0) {
+        timeoutp = NULL;
+    } else {
+        timeout.tv_sec = searchTimelimit;
+        timeout.tv_usec = 0;
+        timeoutp = &timeout;
+    }
     ret = ldap_search_st(st->ld, suffix, scope, pFilter, attrToReturn,
-                         attrsOnly, &timeout, &result);
+                         attrsOnly, timeoutp, &result);
     if (ret != LDAP_SUCCESS) {
         fprintf(stderr, "T%d: failed to search 2, error=0x%02X\n",
                 st->id, ret);