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/tap/tap.h>
15 #undef fcntl_with_lockcheck
19 #include "external-agent.h"
21 static struct agent *agent;
23 static bool correct_key(TDB_DATA key)
25 return key.dsize == strlen("hi")
26 && memcmp(key.dptr, "hi", key.dsize) == 0;
29 static bool correct_data(TDB_DATA data)
31 return data.dsize == strlen("world")
32 && memcmp(data.dptr, "world", data.dsize) == 0;
35 static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
38 ok1(correct_key(key));
39 ok1(correct_data(data));
43 int main(int argc, char *argv[])
45 struct tdb_context *tdb;
49 agent = prepare_external_agent();
51 err(1, "preparing agent");
53 tdb = tdb_open("run-traverse-in-transaction.tdb",
54 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR, 0600);
57 key.dsize = strlen("hi");
58 key.dptr = (void *)"hi";
59 data.dptr = (void *)"world";
60 data.dsize = strlen("world");
62 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
64 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
66 ok1(tdb_transaction_start(tdb) == 0);
67 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
68 == WOULD_HAVE_BLOCKED);
69 tdb_traverse(tdb, traverse, NULL);
71 /* That should *not* release the transaction lock! */
72 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
73 == WOULD_HAVE_BLOCKED);
74 tdb_traverse_read(tdb, traverse, NULL);
76 /* That should *not* release the transaction lock! */
77 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
78 == WOULD_HAVE_BLOCKED);
79 ok1(tdb_transaction_commit(tdb) == 0);
80 /* Now we should be fine. */
81 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))