X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb%2Ftest%2Frun-corrupt.c;h=6f753ea6d46c81c9dbd3f9e388c1f3078c98e30e;hb=ab3df365ce9bcd76379cda8d3a7c188baa3e0a05;hp=eaa326bdd0e70274ce14fec0804feb5ae133100e;hpb=03d4aa56b8bd381db449b36befa6928594cea994;p=ccan diff --git a/ccan/tdb/test/run-corrupt.c b/ccan/tdb/test/run-corrupt.c index eaa326bd..6f753ea6 100644 --- a/ccan/tdb/test/run-corrupt.c +++ b/ccan/tdb/test/run-corrupt.c @@ -9,9 +9,11 @@ #include #include #include +#include #include #include #include +#include "logging.h" static int check(TDB_DATA key, TDB_DATA data, void *private) { @@ -41,9 +43,11 @@ static void tdb_flip_bit(struct tdb_context *tdb, unsigned int bit) ((unsigned char *)tdb->map_ptr)[off] ^= mask; else { unsigned char c; - pread(tdb->fd, &c, 1, off); + if (pread(tdb->fd, &c, 1, off) != 1) + err(1, "pread"); c ^= mask; - pwrite(tdb->fd, &c, 1, off); + if (pwrite(tdb->fd, &c, 1, off) != 1) + err(1, "pwrite"); } } @@ -72,7 +76,8 @@ static void check_test(struct tdb_context *tdb) /* This is how many bytes we expect to be verifiable. */ /* From the file header. */ verifiable = strlen(TDB_MAGIC_FOOD) + 1 - + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t); + + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t) + + 2 * sizeof(uint32_t); /* From the free list chain and hash chains. */ verifiable += 3 * sizeof(tdb_off_t); /* From the record headers & tailer */ @@ -103,8 +108,8 @@ int main(int argc, char *argv[]) plan_tests(4); /* This should use mmap. */ - tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST, - O_CREAT|O_TRUNC|O_RDWR, 0600); + tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST, + O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); if (!tdb) abort(); @@ -112,8 +117,8 @@ int main(int argc, char *argv[]) tdb_close(tdb); /* This should not. */ - tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP, - O_CREAT|O_TRUNC|O_RDWR, 0600); + tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP, + O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); if (!tdb) abort();