diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-09-24 06:49:28 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:38:50 -0500 |
commit | 3bcfc68e0d158b272e0ef87bf585f79a570136ba (patch) | |
tree | c91cf774feb452fc822983ed35e40f1e3720f1be /source4/lib/tdb/tools/tdbtorture.c | |
parent | 6e4ebbed8928d618f56c06bfc0802891c3d939ab (diff) | |
download | samba-3bcfc68e0d158b272e0ef87bf585f79a570136ba.tar.gz samba-3bcfc68e0d158b272e0ef87bf585f79a570136ba.tar.bz2 samba-3bcfc68e0d158b272e0ef87bf585f79a570136ba.zip |
r10468: - terminate tdbtorture quickly when an error is detected
- more workarounds for aix not handling malloc of size 0
(This used to be commit c2b1739c6389503854f55fa8407c55071781eff4)
Diffstat (limited to 'source4/lib/tdb/tools/tdbtorture.c')
-rw-r--r-- | source4/lib/tdb/tools/tdbtorture.c | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 3fc395ba98..eded561106 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -50,7 +50,7 @@ static struct tdb_context *db; static int in_transaction; -static int log_count; +static int error_count; #ifdef PRINTF_ATTRIBUTE static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); @@ -59,7 +59,7 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) { va_list ap; - log_count++; + error_count++; va_start(ap, format); vfprintf(stdout, format, ap); @@ -78,7 +78,7 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) static void fatal(const char *why) { perror(why); - exit(1); + error_count++; } static char *randbuf(int len) @@ -283,37 +283,55 @@ static void usage(void) srand(seed + i); srandom(seed + i); - for (i=0;i<num_loops;i++) { + for (i=0;i<num_loops && error_count == 0;i++) { addrec_db(); } - tdb_traverse_read(db, NULL, NULL); - tdb_traverse(db, traverse_fn, NULL); - tdb_traverse(db, traverse_fn, NULL); + if (error_count == 0) { + tdb_traverse_read(db, NULL, NULL); + tdb_traverse(db, traverse_fn, NULL); + tdb_traverse(db, traverse_fn, NULL); + } tdb_close(db); - if (getpid() == pids[0]) { - for (i=0;i<num_procs-1;i++) { - int status; - if (waitpid(pids[i+1], &status, 0) != pids[i+1]) { - printf("failed to wait for %d\n", - (int)pids[i+1]); - exit(1); - } - if (WEXITSTATUS(status) != 0) { - printf("child %d exited with status %d\n", - (int)pids[i+1], WEXITSTATUS(status)); - exit(1); + if (getpid() != pids[0]) { + return error_count; + } + + for (i=1;i<num_procs;i++) { + int status, j; + pid_t pid; + if (error_count != 0) { + /* try and stop the test on any failure */ + for (j=1;j<num_procs;j++) { + if (pids[j] != 0) { + kill(pids[j], SIGTERM); + } } } - if (log_count == 0) { - printf("OK\n"); + pid = waitpid(-1, &status, 0); + if (pid == -1) { + perror("failed to wait for child\n"); + exit(1); + } + for (j=1;j<num_procs;j++) { + if (pids[j] == pid) break; + } + if (j == num_procs) { + printf("unknown child %d exited!?\n", pid); + exit(1); + } + if (WEXITSTATUS(status) != 0) { + printf("child %d exited with status %d\n", + (int)pid, WEXITSTATUS(status)); + error_count++; } + pids[j] = 0; } - if (log_count != 0) { - exit(1); + if (error_count == 0) { + printf("OK\n"); } return 0; |