X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Frbl.c;h=bb0dda0316c5fdc06ba11759313dfaabb90b98f3;hb=8a641b3dc8b4e2ede5961f95249640c83d3267a6;hp=3f8c6822f1345d034447a0c3577bbaa04d72366a;hpb=1b6ea933129c7a718fc81bedb282a13958a8ea68;p=apps%2Fpfixtools.git diff --git a/postlicyd/rbl.c b/postlicyd/rbl.c index 3f8c682..bb0dda0 100644 --- a/postlicyd/rbl.c +++ b/postlicyd/rbl.c @@ -31,17 +31,17 @@ /* * Copyright © 2007 Pierre Habouzit + * Copyright © 2008 Florent Bruneau */ #include -#include #include #include -#include #include "common.h" #include "rbl.h" #include "str.h" +#include "file.h" #define IPv4_BITS 5 #define IPv4_PREFIX(ip) ((uint32_t)(ip) >> IPv4_BITS) @@ -118,35 +118,19 @@ static int parse_ipv4(const char *s, const char **out, uint32_t *ip) rbldb_t *rbldb_create(const char *file, bool lock) { rbldb_t *db; - const char *map, *p, *end; - struct stat st; - int fd; + file_map_t map; + const char *p, *end; - fd = open(file, O_RDONLY, 0000); - if (fd < 0) { - UNIXERR("open"); + if (!file_map_open(&map, file, false)) { return NULL; } - if (fstat(fd, &st) < 0) { - UNIXERR("fstat"); - close(fd); - return NULL; - } - - p = map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (map == MAP_FAILED) { - UNIXERR("mmap"); - close(fd); - return NULL; - } - close(fd); - - end = map + st.st_size; - while (end > map && end[-1] != '\n') { + p = map.map; + end = map.end; + while (end > p && end[-1] != '\n') { --end; } - if (end != map + st.st_size) { + if (end != map.end) { syslog(LOG_WARNING, "file %s miss a final \\n, ignoring last line", file); } @@ -168,7 +152,7 @@ rbldb_t *rbldb_create(const char *file, bool lock) db->ips[db->len++] = ip; } } - munmap((void*)map, st.st_size); + file_map_close(&map); /* Lookup may perform serveral I/O, so avoid swap. */