1 #define _XOPEN_SOURCE 500
2 #include "lock-tracking.h"
3 #define fcntl fcntl_with_lockcheck
4 #include <ccan/tdb/tdb.h>
5 #include <ccan/tdb/io.c>
6 #include <ccan/tdb/tdb.c>
7 #include <ccan/tdb/lock.c>
8 #include <ccan/tdb/freelist.c>
9 #include <ccan/tdb/traverse.c>
10 #include <ccan/tdb/transaction.c>
11 #include <ccan/tdb/error.c>
12 #include <ccan/tdb/open.c>
13 #include <ccan/tdb/check.c>
14 #include <ccan/tdb/hash.c>
15 #include <ccan/tap/tap.h>
16 #undef fcntl_with_lockcheck
20 #include "external-agent.h"
23 static struct agent *agent;
25 static bool correct_key(TDB_DATA key)
27 return key.dsize == strlen("hi")
28 && memcmp(key.dptr, "hi", key.dsize) == 0;
31 static bool correct_data(TDB_DATA data)
33 return data.dsize == strlen("world")
34 && memcmp(data.dptr, "world", data.dsize) == 0;
37 static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
40 ok1(correct_key(key));
41 ok1(correct_data(data));
45 int main(int argc, char *argv[])
47 struct tdb_context *tdb;
51 agent = prepare_external_agent();
53 err(1, "preparing agent");
55 tdb = tdb_open_ex("run-traverse-in-transaction.tdb",
56 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
57 0600, &taplogctx, NULL);
60 key.dsize = strlen("hi");
61 key.dptr = (void *)"hi";
62 data.dptr = (void *)"world";
63 data.dsize = strlen("world");
65 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
67 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
69 ok1(tdb_transaction_start(tdb) == 0);
70 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
71 == WOULD_HAVE_BLOCKED);
72 tdb_traverse(tdb, traverse, NULL);
74 /* That should *not* release the transaction lock! */
75 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
76 == WOULD_HAVE_BLOCKED);
77 tdb_traverse_read(tdb, traverse, NULL);
79 /* That should *not* release the transaction lock! */
80 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
81 == WOULD_HAVE_BLOCKED);
82 ok1(tdb_transaction_commit(tdb) == 0);
83 /* Now we should be fine. */
84 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))