Browse Source

failtest: fix --debugpath

Calling failpath_string() here leaves the final letter randomly upper or
lower-cased, since call->fail is uninitialized.  This means we sometimes
don't match the debug string.

1) Initialize call->fail here so it will match the debug string.
2) If our calls don't match --debugpath, abort.
3) Don't match the final letter (which may be upper or lower case) 
   when checking we're still on the path.  We could do better, but this is
   only a sanity-check anyway.
Rusty Russell 14 years ago
parent
commit
931f1941d3
1 changed files with 14 additions and 4 deletions
  1. 14 4
      ccan/failtest/failtest.c

+ 14 - 4
ccan/failtest/failtest.c

@@ -523,7 +523,12 @@ static bool should_fail(struct failtest_call *call)
 
 
 	/* Attach debugger if they asked for it. */
 	/* Attach debugger if they asked for it. */
 	if (debugpath) {
 	if (debugpath) {
-		char *path = failpath_string();
+		char *path;
+
+		/* Pretend this last call matches whatever path wanted:
+		 * keeps valgrind happy. */
+		call->fail = cisupper(debugpath[strlen(debugpath)-1]);
+		path = failpath_string();
 
 
 		if (streq(path, debugpath)) {
 		if (streq(path, debugpath)) {
 			char str[80];
 			char str[80];
@@ -534,9 +539,14 @@ static bool should_fail(struct failtest_call *call)
 				getpid(), getpid());
 				getpid(), getpid());
 			if (system(str) == 0)
 			if (system(str) == 0)
 				sleep(5);
 				sleep(5);
-		} else if (!strstarts(path, debugpath)) {
-			fprintf(stderr, "--debugpath not followed: %s\n", path);
-			debugpath = NULL;
+		} else {
+			/* Ignore last character: could be upper or lower. */
+			path[strlen(path)-1] = '\0';
+			if (!strstarts(debugpath, path)) {
+				fprintf(stderr,
+					"--debugpath not followed: %s\n", path);
+				debugpath = NULL;
+			}
 		}
 		}
 		free(path);
 		free(path);
 	}
 	}