diff options
author | Alex Dowad <alexinbeijing@gmail.com> | 2014-04-14 22:00:07 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-04-25 10:19:36 +0300 |
commit | f7447b2cb47524480aae824df80927a4fdca3c93 (patch) | |
tree | 65f72ec033ebc671aa4691cd3ad84995a7549eec | |
parent | fe837d542866d7f30741c4a7f9ff2391dc8451a3 (diff) | |
download | squark-f7447b2cb47524480aae824df80927a4fdca3c93.tar.bz2 squark-f7447b2cb47524480aae824df80927a4fdca3c93.tar.xz |
filterdb: report errors
-rw-r--r-- | src/filterdb.c | 23 |
1 files changed, 18 insertions, 5 deletions
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 <string.h> #include <sys/mman.h> #include <sys/stat.h> +#include <string.h> +#include <errno.h> #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; |