From f7447b2cb47524480aae824df80927a4fdca3c93 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Mon, 14 Apr 2014 22:00:07 +0200 Subject: filterdb: report errors --- src/filterdb.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/filterdb.c') diff --git a/src/filterdb.c b/src/filterdb.c index c359ce6..0e842d3 100644 --- a/src/filterdb.c +++ b/src/filterdb.c @@ -3,8 +3,11 @@ #include #include #include +#include +#include #include "filterdb.h" +#include "reporting.h" #define PAGE_SIZE 4096 #define ALIGN(s,a) (((s) + a - 1) & ~(a - 1)) @@ -32,8 +35,10 @@ static int sqdb_allocate(struct sqdb *db, size_t s, int wr) return old_size; } - if (wr && ftruncate(db->fd, new_size) < 0) + if (wr && ftruncate(db->fd, new_size) < 0) { + report_error("Error occurred while resizing filter DB file: %s\n", strerror(errno)); return -1; + } if (db->mmap_base == NULL) { if (wr) @@ -43,8 +48,10 @@ static int sqdb_allocate(struct sqdb *db, size_t s, int wr) base = mremap(db->mmap_base, ALIGN(old_size, PAGE_SIZE), new_size, MREMAP_MAYMOVE); } - if (base == MAP_FAILED) + if (base == MAP_FAILED) { + report_error("Couldn't map filter DB file into address space. Error: %s\n", strerror(errno)); return -1; + } db->mmap_base = base; db->file_length += ALIGN(s, 16); @@ -57,10 +64,14 @@ int sqdb_open(struct sqdb *db, const char *fn) struct stat st; db->fd = open(fn, O_RDONLY); - if (db->fd < 0) + if (db->fd < 0) { + report_error("Couldn't open filter DB file. Error: %s\n", strerror(errno)); return -1; + } - fstat(db->fd, &st); + if(fstat(db->fd, &st) < 0) + report_error("Error occurred while checking file attributes of filter DB: %s\n", + strerror(errno)); db->file_length = 0; db->mmap_base = NULL; @@ -75,8 +86,10 @@ int sqdb_create(struct sqdb *db, const char *fn) int rc; db->fd = open(fn, O_CREAT | O_TRUNC | O_RDWR, 0666); - if (db->fd < 0) + if (db->fd < 0) { + report_error("Couldn't create filter DB file. Error: %s\n", strerror(errno)); return -1; + } db->file_length = 0; db->mmap_base = NULL; -- cgit v1.2.3