X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftest%2Frun-die-during-transaction.c;h=aa6b40f6bbad9eb5246d03334ff9b6c0a738cf9f;hp=c5f802c22e9edcad94a11c3f4892ce7a758e880a;hb=100444225380d3f5ca29424ea54703d308c7c651;hpb=a153d09b979182e8586d4501ea687bcdd466dabc diff --git a/ccan/tdb/test/run-die-during-transaction.c b/ccan/tdb/test/run-die-during-transaction.c index c5f802c2..aa6b40f6 100644 --- a/ccan/tdb/test/run-die-during-transaction.c +++ b/ccan/tdb/test/run-die-during-transaction.c @@ -20,6 +20,7 @@ static int ftruncate_check(int fd, off_t length); #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ static int ftruncate_check(int fd, off_t length); #include #include #include "external-agent.h" +#include "logging.h" #undef write #undef pwrite @@ -34,29 +36,11 @@ static int ftruncate_check(int fd, off_t length); #undef ftruncate static bool in_transaction; -static bool suppress_logging; static int target, current; static jmp_buf jmpbuf; #define TEST_DBNAME "run-die-during-transaction.tdb" #define KEY_STRING "helloworld" -static void taplog(struct tdb_context *tdb, - enum tdb_debug_level level, - const char *fmt, ...) -{ - va_list ap; - char line[200]; - - if (suppress_logging) - return; - - va_start(ap, fmt); - vsprintf(line, fmt, ap); - va_end(ap); - - diag("%s", line); -} - static void maybe_die(int fd) { if (in_transaction && current++ == target) { @@ -109,12 +93,15 @@ static bool test_death(enum operation op, struct agent *agent) { struct tdb_context *tdb = NULL; TDB_DATA key; - struct tdb_logging_context logctx = { taplog, NULL }; enum agent_return ret; int needed_recovery = 0; current = target = 0; reset: + unlink(TEST_DBNAME); + tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP, + O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); + if (setjmp(jmpbuf) != 0) { /* We're partway through. Simulate our death. */ close(tdb->fd); @@ -170,10 +157,6 @@ reset: goto reset; } - unlink(TEST_DBNAME); - tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP, - O_CREAT|O_TRUNC|O_RDWR, 0600, &logctx, NULL); - /* Put key for agent to fetch. */ key.dsize = strlen(KEY_STRING); key.dptr = (void *)KEY_STRING;