1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
Index: src/network_backends.h
===================================================================
--- src/network_backends.h (revision 2825)
+++ src/network_backends.h (revision 2827)
@@ -31,7 +31,7 @@
# include <sys/uio.h>
#endif
-#if defined HAVE_SYS_MMAN_H && defined HAVE_MMAP
+#if defined HAVE_SYS_MMAN_H && defined HAVE_MMAP && defined ENABLE_MMAP
# define USE_MMAP
# include <sys/mman.h>
/* NetBSD 1.3.x needs it */
Index: src/mod_compress.c
===================================================================
--- src/mod_compress.c (revision 2825)
+++ src/mod_compress.c (revision 2827)
@@ -485,7 +485,7 @@
return -1;
}
-
+#ifdef USE_MMAP
if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
@@ -499,7 +499,24 @@
return -1;
}
+#else
+ start = malloc(sce->st.st_size);
+ if (NULL == start || sce->st.st_size != read(ifd, start, sce->st.st_size)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno));
+ close(ofd);
+ close(ifd);
+ free(start);
+
+ /* Remove the incomplete cache file, so that later hits aren't served from it */
+ if (-1 == unlink(p->ofn->ptr)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno));
+ }
+
+ return -1;
+ }
+#endif
+
switch(type) {
#ifdef USE_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
@@ -530,7 +547,12 @@
}
}
+#ifdef USE_MMAP
munmap(start, sce->st.st_size);
+#else
+ free(start);
+#endif
+
close(ofd);
close(ifd);
@@ -571,14 +593,24 @@
return -1;
}
-
+#ifdef USE_MMAP
if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
close(ifd);
return -1;
}
+#else
+ start = malloc(sce->st.st_size);
+ if (NULL == start || sce->st.st_size != read(ifd, start, sce->st.st_size)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno));
+ close(ifd);
+ free(start);
+ return -1;
+ }
+#endif
+
switch(type) {
#ifdef USE_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
@@ -598,7 +630,11 @@
break;
}
+#ifdef USE_MMAP
munmap(start, sce->st.st_size);
+#else
+ free(start);
+#endif
close(ifd);
if (ret != 0) return -1;
@@ -826,7 +862,7 @@
}
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
/* let mod_staticfile handle the cached compressed files, physical path was modified */
- return p->conf.compress_cache_dir->used ? HANDLER_GO_ON : HANDLER_FINISHED;
+ return (use_etag && p->conf.compress_cache_dir->used) ? HANDLER_GO_ON : HANDLER_FINISHED;
}
}
}
Index: configure.ac
===================================================================
--- configure.ac (revision 2825)
+++ configure.ac (revision 2827)
@@ -569,7 +569,22 @@
fi
fi
+# disable mmap by default; if a mmapped file gets truncated, the process gets a SIGBUS signal
+# on reading the truncated area which we can't handle (yet).
+# lighttpd may always use mmap with files it owns (created tmp files)
+AC_ARG_ENABLE(mmap,
+ AC_HELP_STRING([--enable-mmap],[use mmap if available (DANGEROUS, allows local users to trigger SIGBUS crashes)]),
+ [case "${enableval}" in
+ yes) mmap=true ;;
+ no) mmap=false ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-mmap) ;;
+ esac],[mmap=false])
+if teest x$mmap = xtrue; then
+ AC_DEFINE(ENABLE_MMAP, [1], [Use mmap if available])
+fi
+
+
AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = xyes)
dnl check for fastcgi lib, for the tests only
|