1 #include "tdb2-source.h"
2 /* We had a bug where we marked the tdb read-only for a tdb_traverse_read.
3 * If we then expanded the tdb, we would remap read-only, and later SEGV. */
4 #include <ccan/tap/tap.h>
5 #include "external-agent.h"
8 static bool file_larger(int fd
, tdb_len_t size
)
13 return st
.st_size
!= size
;
16 static unsigned add_records_to_grow(struct agent
*agent
, int fd
, tdb_len_t size
)
20 for (i
= 0; !file_larger(fd
, size
); i
++) {
22 sprintf(data
, "%i", i
);
23 if (external_agent_operation(agent
, STORE
, data
) != SUCCESS
)
26 diag("Added %u records to grow file", i
);
30 int main(int argc
, char *argv
[])
34 struct tdb_context
*tdb
;
35 struct tdb_data d
= tdb_mkdata("hello", 5);
36 const char filename
[] = "run-remap-in-read_traverse.tdb";
40 agent
= prepare_external_agent();
42 tdb
= tdb_open(filename
, TDB_DEFAULT
,
43 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
45 ok1(external_agent_operation(agent
, OPEN
, filename
) == SUCCESS
);
46 i
= add_records_to_grow(agent
, tdb
->file
->fd
, tdb
->file
->map_size
);
49 ok1(tdb_traverse(tdb
, NULL
, NULL
) == i
);
51 /* Now store something! */
52 ok1(tdb_store(tdb
, d
, d
, TDB_INSERT
) == 0);
53 ok1(tap_log_messages
== 0);
55 free_external_agent(agent
);