s3:net_util: add some const to sockaddr_storage
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-remap-in-read_traverse.c
blobd784ca34074ec7f8b8fe0cee6c957e60f42d578b
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"
14 #include "logging.h"
16 static bool file_larger(int fd, tdb_len_t size)
18 struct stat st;
20 fstat(fd, &st);
21 return st.st_size != size;
24 static unsigned add_records_to_grow(struct agent *agent, int fd, tdb_len_t size)
26 unsigned int i;
28 for (i = 0; !file_larger(fd, size); i++) {
29 char data[20];
30 sprintf(data, "%i", i);
31 if (external_agent_operation(agent, STORE, data) != SUCCESS)
32 return 0;
34 diag("Added %u records to grow file", i);
35 return i;
38 int main(int argc, char *argv[])
40 unsigned int i;
41 struct agent *agent;
42 struct tdb_context *tdb;
43 struct tdb_data d = tdb_mkdata("hello", 5);
44 const char filename[] = "run-remap-in-read_traverse.tdb";
46 plan_tests(4);
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);
56 /* Do a traverse. */
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);
62 tdb_close(tdb);
63 free_external_agent(agent);
64 return exit_status();