1 /* We had a bug where we marked the tdb read-only for a tdb_traverse_read.
2 * If we then expanded the tdb, we would remap read-only, and later SEGV. */
3 #include <ccan/tdb2/tdb.c>
4 #include <ccan/tdb2/free.c>
5 #include <ccan/tdb2/lock.c>
6 #include <ccan/tdb2/io.c>
7 #include <ccan/tdb2/hash.c>
8 #include <ccan/tdb2/check.c>
9 #include <ccan/tdb2/traverse.c>
10 #include <ccan/tap/tap.h>
11 #include "external-agent.h"
14 static bool file_larger(int fd, tdb_len_t size)
19 return st.st_size != size;
22 static unsigned add_records_to_grow(struct agent *agent, int fd, tdb_len_t size)
26 for (i = 0; !file_larger(fd, size); i++) {
28 sprintf(data, "%i", i);
29 if (external_agent_operation(agent, STORE, data) != SUCCESS)
32 diag("Added %u records to grow file", i);
36 int main(int argc, char *argv[])
40 struct tdb_context *tdb;
41 struct tdb_data d = { (unsigned char *)"hello", 5 };
42 const char filename[] = "run-remap-in-read_traverse.tdb";
46 agent = prepare_external_agent();
48 tdb = tdb_open(filename, TDB_DEFAULT,
49 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
51 ok1(external_agent_operation(agent, OPEN, filename) == SUCCESS);
52 i = add_records_to_grow(agent, tdb->fd, tdb->map_size);
54 /* Do a read traverse. */
55 ok1(tdb_traverse_read(tdb, NULL, NULL) == i);
57 /* Now store something! */
58 ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
59 ok1(tap_log_messages == 0);