summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunbit <info@unbit.it>2014-12-06 07:03:32 +0100
committerunbit <info@unbit.it>2014-12-06 07:03:32 +0100
commit3368a26ad352db8bd5a2770e6fce896875415056 (patch)
treeba2d942b5453e896b83815b81886bdd9fbb2fe39
parentc0d61bc6a48e5704882e0c1b26fea20f50fd0649 (diff)
parent5c2bb347084ad43bacd56620d899d7bad08c65c3 (diff)
downloaduwsgi-1.4.tar.gz
Merge pull request #788 from dpetzold/mmap-checkuwsgi-1.4
Fix mmap error check in 1.4.
-rw-r--r--core/cache.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/core/cache.c b/core/cache.c
index 9977cc0c..f027bd3f 100644
--- a/core/cache.c
+++ b/core/cache.c
@@ -58,20 +58,28 @@ void uwsgi_init_cache() {
exit(1);
}
uwsgi.cache_items = (struct uwsgi_cache_item *) mmap(NULL, uwsgi.cache_filesize, PROT_READ | PROT_WRITE, MAP_SHARED, cache_fd, 0);
+ if (uwsgi.cache_items == MAP_FAILED) {
+ uwsgi_log("Unable to mmap %llu bytes.\n", uwsgi.cache_filesize);
+ uwsgi_error("mmap()");
+ exit(1);
+ }
+
uwsgi_cache_fix();
}
else {
- uwsgi.cache_items = (struct uwsgi_cache_item *) mmap(NULL, (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items) + (uwsgi.cache_blocksize * uwsgi.cache_max_items), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+ ssize_t cache_size = (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items) + (uwsgi.cache_blocksize * uwsgi.cache_max_items);
+ uwsgi.cache_items = (struct uwsgi_cache_item *) mmap(NULL, cache_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+ if (uwsgi.cache_items == MAP_FAILED) {
+ uwsgi_log("Unable to mmap %llu bytes.\n", cache_size);
+ uwsgi_error("mmap()");
+ exit(1);
+ }
int i;
for (i = 0; i < (int) uwsgi.cache_max_items; i++) {
memset(&uwsgi.cache_items[i], 0, sizeof(struct uwsgi_cache_item));
}
}
- if (!uwsgi.cache_items) {
- uwsgi_error("mmap()");
- exit(1);
- }
/*
uwsgi.cache = mmap(NULL, uwsgi.cache_blocksize * uwsgi.cache_max_items, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);