1 #include "ntdb-source.h"
2 /* We had a bug where we marked the ntdb read-only for a ntdb_traverse_read.
3 * If we then expanded the ntdb, we would remap read-only, and later SEGV. */
4 #include "tap-interface.h"
5 #include "external-agent.h"
8 static bool file_larger(int fd
, ntdb_len_t size
)
13 return st
.st_size
!= size
;
16 static unsigned add_records_to_grow(struct agent
*agent
, int fd
, ntdb_len_t size
)
20 for (i
= 0; !file_larger(fd
, size
); i
++) {
22 sprintf(data
, "%i=%i", 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 ntdb_context
*ntdb
;
35 NTDB_DATA d
= ntdb_mkdata("hello", 5);
36 const char filename
[] = "run-remap-in-read_traverse.ntdb";
40 agent
= prepare_external_agent();
42 ntdb
= ntdb_open(filename
, MAYBE_NOSYNC
,
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
, ntdb
->file
->fd
, ntdb
->file
->map_size
);
49 ok1(ntdb_traverse(ntdb
, NULL
, NULL
) == i
);
51 /* Now store something! */
52 ok1(ntdb_store(ntdb
, d
, d
, NTDB_INSERT
) == 0);
53 ok1(tap_log_messages
== 0);
55 free_external_agent(agent
);