Skip to content

Commit

Permalink
Merge pull request #788 from dpetzold/mmap-check
Browse files Browse the repository at this point in the history
Fix mmap error check in 1.4.
  • Loading branch information
unbit committed Dec 6, 2014
2 parents c0d61bc + 5c2bb34 commit 3368a26
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3368a26

Please sign in to comment.