1 /* We should be able to tdb_check a O_RDONLY tdb, and we were previously allowed
2 * to tdb_check() inside a transaction (though that's paranoia!). */
3 #include "tdb2-source.h"
4 #include <ccan/tap/tap.h>
9 int main(int argc
, char *argv
[])
11 struct tdb_context
*tdb
;
13 union tdb_attribute hsize
;
15 hsize
.base
.attr
= TDB_ATTRIBUTE_TDB1_HASHSIZE
;
16 hsize
.base
.next
= &tap_log_attr
;
17 hsize
.tdb1_hashsize
.hsize
= 1024;
20 tdb
= tdb_open("run-readonly-check.tdb1",
22 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &hsize
);
25 key
.dsize
= strlen("hi");
26 key
.dptr
= (void *)"hi";
27 data
.dsize
= strlen("world");
28 data
.dptr
= (void *)"world";
30 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == TDB_SUCCESS
);
31 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
33 /* We are also allowed to do a check inside a transaction. */
34 ok1(tdb_transaction_start(tdb
) == TDB_SUCCESS
);
35 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
36 ok1(tdb_close(tdb
) == 0);
38 tdb
= tdb_open("run-readonly-check.tdb1",
39 TDB_DEFAULT
, O_RDONLY
, 0, &tap_log_attr
);
42 ok1(tdb_store(tdb
, key
, data
, TDB_MODIFY
) == TDB_ERR_RDONLY
);
43 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
44 ok1(tdb_close(tdb
) == 0);