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/open.c>
5 #include <ccan/tdb2/free.c>
6 #include <ccan/tdb2/lock.c>
7 #include <ccan/tdb2/io.c>
8 #include <ccan/tdb2/hash.c>
9 #include <ccan/tdb2/check.c>
10 #include <ccan/tdb2/traverse.c>
11 #include <ccan/tdb2/transaction.c>
12 #include <ccan/tap/tap.h>
13 #include "external-agent.h"
16 static bool file_larger(int fd
, tdb_len_t size
)
21 return st
.st_size
!= size
;
24 static unsigned add_records_to_grow(struct agent
*agent
, int fd
, tdb_len_t size
)
28 for (i
= 0; !file_larger(fd
, size
); i
++) {
30 sprintf(data
, "%i", i
);
31 if (external_agent_operation(agent
, STORE
, data
) != SUCCESS
)
34 diag("Added %u records to grow file", i
);
38 int main(int argc
, char *argv
[])
42 struct tdb_context
*tdb
;
43 struct tdb_data d
= tdb_mkdata("hello", 5);
44 const char filename
[] = "run-remap-in-read_traverse.tdb";
48 agent
= prepare_external_agent();
50 tdb
= tdb_open(filename
, TDB_DEFAULT
,
51 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
53 ok1(external_agent_operation(agent
, OPEN
, filename
) == SUCCESS
);
54 i
= add_records_to_grow(agent
, tdb
->file
->fd
, tdb
->file
->map_size
);
57 ok1(tdb_traverse(tdb
, NULL
, NULL
) == i
);
59 /* Now store something! */
60 ok1(tdb_store(tdb
, d
, d
, TDB_INSERT
) == 0);
61 ok1(tap_log_messages
== 0);
63 free_external_agent(agent
);