]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tools/tdbtorture.c
tdb2: fix tools compilation.
[ccan] / ccan / tdb2 / tools / tdbtorture.c
index 5dddf99a7cfa47d8807df251c3bc902a8e890fc5..52cab665d1393e63a8839dc3ad17619915db4a54 100644 (file)
@@ -24,7 +24,6 @@
 #define TRANSACTION_PREPARE_PROB 2
 #define LOCKSTORE_PROB 5
 #define TRAVERSE_PROB 20
-#define TRAVERSE_READ_PROB 20
 #define TRAVERSE_MOD_PROB 100
 #define TRAVERSE_ABORT_PROB 500
 #define CULL_PROB 100
@@ -43,16 +42,10 @@ static int count_pipe;
 static union tdb_attribute log_attr;
 static union tdb_attribute seed_attr;
 
-#ifdef PRINTF_FMT
-static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...) PRINTF_FMT(4,5);
-#endif
-static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...)
+static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
+                   void *private, const char *message)
 {
-       va_list ap;
-
-       va_start(ap, format);
-       vfprintf(stdout, format, ap);
-       va_end(ap);
+       fputs(message, stdout);
        fflush(stdout);
 #if 0
        {
@@ -71,10 +64,11 @@ static void segv_handler(int signal, siginfo_t *info, void *p)
 {
        char string[100];
 
-       sprintf(string, "%u: death at %p (map_ptr %p, map_size %llu)\n",
-               getpid(), info->si_addr, db->map_ptr, db->map_size);
-       write(2, string, strlen(string));
-       sleep(60);
+       sprintf(string, "%u: death at %p (map_ptr %p, map_size %zu)\n",
+               getpid(), info->si_addr, db->file->map_ptr,
+               (size_t)db->file->map_size);
+       if (write(2, string, strlen(string)) > 0)
+               sleep(60);
        _exit(11);
 }      
 
@@ -202,7 +196,7 @@ static void addrec_db(void)
 #if LOCKSTORE_PROB
        if (random() % LOCKSTORE_PROB == 0) {
                tdb_chainlock(db, key);
-               data = tdb_fetch(db, key);
+               tdb_fetch(db, key, &data);
                if (tdb_store(db, key, data, TDB_REPLACE) != 0) {
                        fatal("tdb_store failed");
                }
@@ -222,17 +216,8 @@ static void addrec_db(void)
        }
 #endif
 
-#if TRAVERSE_READ_PROB
-       if (in_traverse == 0 && random() % TRAVERSE_READ_PROB == 0) {
-               in_traverse++;
-               tdb_traverse_read(db, NULL, NULL);
-               in_traverse--;
-               goto next;
-       }
-#endif
-
-       data = tdb_fetch(db, key);
-       if (data.dptr) free(data.dptr);
+       if (tdb_fetch(db, key, &data) == TDB_SUCCESS)
+               free(data.dptr);
 
 next:
        free(k);
@@ -259,7 +244,8 @@ static void usage(void)
 static void send_count_and_suicide(int sig)
 {
        /* This ensures our successor can continue where we left off. */
-       write(count_pipe, &loopnum, sizeof(loopnum));
+       if (write(count_pipe, &loopnum, sizeof(loopnum)) != sizeof(loopnum))
+               exit(2);
        /* This gives a unique signature. */
        kill(getpid(), SIGUSR2);
 }
@@ -296,7 +282,7 @@ static int run_child(int i, int seed, unsigned num_loops, unsigned start)
        }
 
        if (error_count == 0) {
-               tdb_traverse_read(db, NULL, NULL);
+               tdb_traverse(db, NULL, NULL);
 #if TRANSACTION_PROB
                if (always_transaction) {
                        while (in_transaction) {
@@ -449,8 +435,11 @@ int main(int argc, char * const *argv)
                            || WTERMSIG(status) == SIGUSR1) {
                                /* SIGUSR2 means they wrote to pipe. */
                                if (WTERMSIG(status) == SIGUSR2) {
-                                       read(pfds[0], &done[j],
-                                            sizeof(done[j]));
+                                       if (read(pfds[0], &done[j],
+                                                sizeof(done[j]))
+                                           != sizeof(done[j]))
+                                               err(1,
+                                                   "Short read from child?");
                                }
                                pids[j] = fork();
                                if (pids[j] == 0)