Browse Source

[mod_compress,mod_deflate] try mmap MAP_PRIVATE

try mmap MAP_PRIVATE if mmap MAP_SHARED fails with errno == EINVAL
Some file systems such as jffs2 and btrfs might not support MAP_SHARED
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
e4ed2ed4ae
  1. 6
      src/mod_compress.c
  2. 5
      src/mod_deflate.c

6
src/mod_compress.c

@ -563,7 +563,8 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, bu
}
#ifdef USE_MMAP
if (MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
if (MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))
|| (errno == EINVAL && MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0)))) {
mapped = 1;
signal(SIGBUS, sigbus_handler);
sigbus_jmp_valid = 1;
@ -690,7 +691,8 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p,
}
#ifdef USE_MMAP
if (MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
if (MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))
|| (errno == EINVAL && MAP_FAILED != (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0)))) {
mapped = 1;
signal(SIGBUS, sigbus_handler);
sigbus_jmp_valid = 1;

5
src/mod_deflate.c

@ -792,9 +792,8 @@ static int mod_deflate_file_chunk(server *srv, connection *con, handler_ctx *hct
/* we have more to send than we can mmap() at once */
if (we_want_to_send > to_mmap) we_want_to_send = to_mmap;
if (MAP_FAILED == (c->file.mmap.start = mmap(0, (size_t)to_mmap, PROT_READ, MAP_SHARED, c->file.fd, c->file.mmap.offset))) {
/* close it here, otherwise we'd have to set FD_CLOEXEC */
if (MAP_FAILED == (c->file.mmap.start = mmap(0, (size_t)to_mmap, PROT_READ, MAP_SHARED, c->file.fd, c->file.mmap.offset))
&& (errno != EINVAL || MAP_FAILED == (c->file.mmap.start = mmap(0, (size_t)to_mmap, PROT_READ, MAP_PRIVATE, c->file.fd, c->file.mmap.offset)))) {
log_error_write(srv, __FILE__, __LINE__, "ssbd", "mmap failed:",
strerror(errno), c->file.name, c->file.fd);

Loading…
Cancel
Save