]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd-branch.diff
- up to Revision 2621:
[packages/lighttpd.git] / lighttpd-branch.diff
1 Index: ChangeLog
2 ===================================================================
3 Index: .cvsignore
4 ===================================================================
5 Index: src/.cvsignore
6 ===================================================================
7 Index: src/configfile-glue.c
8 ===================================================================
9 --- src/configfile-glue.c       (.../tags/lighttpd-1.4.23)
10 +++ src/configfile-glue.c       (.../branches/lighttpd-1.4.x)
11 @@ -103,7 +103,6 @@
12                                         if (e != ds->value->ptr && !*e && l >=0 && l <= 65535) {
13                                                 *((unsigned short *)(cv[i].destination)) = l;
14                                                 break;
15 -
16                                         }
17                                 }
18  
19 @@ -112,10 +111,40 @@
20                                 return -1;
21                         }
22                         default:
23 -                               log_error_write(srv, __FILE__, __LINE__, "ssds", "unexpected type for key:", cv[i].key, du->type, "expected a integer, range 0 ... 65535");
24 +                               log_error_write(srv, __FILE__, __LINE__, "ssds", "unexpected type for key:", cv[i].key, du->type, "expected a short integer, range 0 ... 65535");
25                                 return -1;
26                         }
27                         break;
28 +               case T_CONFIG_INT:
29 +                       switch(du->type) {
30 +                       case TYPE_INTEGER: {
31 +                               data_integer *di = (data_integer *)du;
32 +
33 +                               *((unsigned int *)(cv[i].destination)) = di->value;
34 +                               break;
35 +                       }
36 +                       case TYPE_STRING: {
37 +                               data_string *ds = (data_string *)du;
38 +
39 +                               if (ds->value->ptr && *ds->value->ptr) {
40 +                                       char *e;
41 +                                       long l = strtol(ds->value->ptr, &e, 10);
42 +                                       if (e != ds->value->ptr && !*e && l >= 0) {
43 +                                               *((unsigned int *)(cv[i].destination)) = l;
44 +                                               break;
45 +                                       }
46 +                               }
47 +
48 +
49 +                               log_error_write(srv, __FILE__, __LINE__, "ssb", "got a string but expected an integer:", cv[i].key, ds->value);
50 +
51 +                               return -1;
52 +                       }
53 +                       default:
54 +                               log_error_write(srv, __FILE__, __LINE__, "ssds", "unexpected type for key:", cv[i].key, du->type, "expected an integer, range 0 ... 4294967295");
55 +                               return -1;
56 +                       }
57 +                       break;
58                 case T_CONFIG_BOOLEAN:
59                         if (du->type == TYPE_STRING) {
60                                 data_string *ds = (data_string *)du;
61 Index: src/mod_cgi.c
62 ===================================================================
63 --- src/mod_cgi.c       (.../tags/lighttpd-1.4.23)
64 +++ src/mod_cgi.c       (.../branches/lighttpd-1.4.x)
65 @@ -56,6 +56,7 @@
66  
67  typedef struct {
68         array *cgi;
69 +       unsigned short execute_x_only;
70  } plugin_config;
71  
72  typedef struct {
73 @@ -151,6 +152,7 @@
74  
75         config_values_t cv[] = {
76                 { "cgi.assign",                  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
77 +               { "cgi.execute-x-only",          NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },     /* 1 */
78                 { NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET}
79         };
80  
81 @@ -165,8 +167,10 @@
82                 assert(s);
83  
84                 s->cgi    = array_init();
85 +               s->execute_x_only = 0;
86  
87                 cv[0].destination = s->cgi;
88 +               cv[1].destination = &(s->execute_x_only);
89  
90                 p->config_storage[i] = s;
91  
92 @@ -580,12 +584,9 @@
93  #if 0
94                                 log_error_write(srv, __FILE__, __LINE__, "sd", "(debug) cgi exited fine, pid:", pid);
95  #endif
96 -                               pid = 0;
97 -
98                                 return HANDLER_GO_ON;
99                         } else {
100                                 log_error_write(srv, __FILE__, __LINE__, "sd", "cgi died, pid:", pid);
101 -                               pid = 0;
102                                 return HANDLER_GO_ON;
103                         }
104                 }
105 @@ -1005,7 +1006,7 @@
106                         args[i++] = cgi_handler->ptr;
107                 }
108                 args[i++] = con->physical.path->ptr;
109 -               args[i++] = NULL;
110 +               args[i  ] = NULL;
111  
112                 /* search for the last / */
113                 if (NULL != (c = strrchr(con->physical.path->ptr, '/'))) {
114 @@ -1018,8 +1019,6 @@
115                         *c = '/';
116                 }
117  
118 -               openDevNull(STDERR_FILENO);
119 -
120                 /* we don't need the client socket */
121                 for (i = 3; i < 256; i++) {
122                         if (i != srv->errorlog_fd) close(i);
123 @@ -1198,6 +1197,8 @@
124  
125                         if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.assign"))) {
126                                 PATCH(cgi);
127 +                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.execute-x-only"))) {
128 +                               PATCH(execute_x_only);
129                         }
130                 }
131         }
132 @@ -1220,6 +1221,7 @@
133  
134         if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) return HANDLER_GO_ON;
135         if (!S_ISREG(sce->st.st_mode)) return HANDLER_GO_ON;
136 +       if (p->conf.execute_x_only == 1 && (sce->st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) return HANDLER_GO_ON;
137  
138         s_len = fn->used - 1;
139  
140 Index: src/network_write.c
141 ===================================================================
142 --- src/network_write.c (.../tags/lighttpd-1.4.23)
143 +++ src/network_write.c (.../branches/lighttpd-1.4.x)
144 @@ -46,15 +46,27 @@
145                         toSend = c->mem->used - 1 - c->offset;
146  #ifdef __WIN32
147                         if ((r = send(fd, offset, toSend, 0)) < 0) {
148 -                               log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
149 +                               /* no error handling for windows... */
150 +                               log_error_write(srv, __FILE__, __LINE__, "ssd", "send failed: ", strerror(errno), fd);
151  
152                                 return -1;
153                         }
154  #else
155                         if ((r = write(fd, offset, toSend)) < 0) {
156 -                               log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
157 +                               switch (errno) {
158 +                               case EAGAIN:
159 +                               case EINTR:
160 +                                       r = 0;
161 +                                       break;
162 +                               case EPIPE:
163 +                               case ECONNRESET:
164 +                                       return -2;
165 +                               default:
166 +                                       log_error_write(srv, __FILE__, __LINE__, "ssd",
167 +                                               "write failed:", strerror(errno), fd);
168  
169 -                               return -1;
170 +                                       return -1;
171 +                               }
172                         }
173  #endif
174  
175 @@ -98,7 +110,7 @@
176                                 return -1;
177                         }
178  
179 -#if defined USE_MMAP
180 +#ifdef USE_MMAP
181                         if (MAP_FAILED == (p = mmap(0, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
182                                 log_error_write(srv, __FILE__, __LINE__, "ss", "mmap failed: ", strerror(errno));
183  
184 @@ -109,13 +121,26 @@
185                         close(ifd);
186  
187                         if ((r = write(fd, p + offset, toSend)) <= 0) {
188 -                               log_error_write(srv, __FILE__, __LINE__, "ss", "write failed: ", strerror(errno));
189 -                               munmap(p, sce->st.st_size);
190 -                               return -1;
191 +                               switch (errno) {
192 +                               case EAGAIN:
193 +                               case EINTR:
194 +                                       r = 0;
195 +                                       break;
196 +                               case EPIPE:
197 +                               case ECONNRESET:
198 +                                       munmap(p, sce->st.st_size);
199 +                                       return -2;
200 +                               default:
201 +                                       log_error_write(srv, __FILE__, __LINE__, "ssd",
202 +                                               "write failed:", strerror(errno), fd);
203 +                                       munmap(p, sce->st.st_size);
204 +
205 +                                       return -1;
206 +                               }
207                         }
208  
209                         munmap(p, sce->st.st_size);
210 -#else
211 +#else /* USE_MMAP */
212                         buffer_prepare_copy(srv->tmp_buf, toSend);
213  
214                         lseek(ifd, offset, SEEK_SET);
215 @@ -127,12 +152,33 @@
216                         }
217                         close(ifd);
218  
219 -                       if (-1 == (r = send(fd, srv->tmp_buf->ptr, toSend, 0))) {
220 -                               log_error_write(srv, __FILE__, __LINE__, "ss", "write: ", strerror(errno));
221 +#ifdef __WIN32
222 +                       if ((r = send(fd, srv->tmp_buf->ptr, toSend, 0)) < 0) {
223 +                               /* no error handling for windows... */
224 +                               log_error_write(srv, __FILE__, __LINE__, "ssd", "send failed: ", strerror(errno), fd);
225  
226                                 return -1;
227                         }
228 -#endif
229 +#else /* __WIN32 */
230 +                       if ((r = write(fd, srv->tmp_buf->ptr, toSend)) < 0) {
231 +                               switch (errno) {
232 +                               case EAGAIN:
233 +                               case EINTR:
234 +                                       r = 0;
235 +                                       break;
236 +                               case EPIPE:
237 +                               case ECONNRESET:
238 +                                       return -2;
239 +                               default:
240 +                                       log_error_write(srv, __FILE__, __LINE__, "ssd",
241 +                                               "write failed:", strerror(errno), fd);
242 +
243 +                                       return -1;
244 +                               }
245 +                       }
246 +#endif /* __WIN32 */
247 +#endif /* USE_MMAP */
248 +
249                         c->offset += r;
250                         cq->bytes_out += r;
251  
252 Index: src/mod_secure_download.c
253 ===================================================================
254 --- src/mod_secure_download.c   (.../tags/lighttpd-1.4.23)
255 +++ src/mod_secure_download.c   (.../branches/lighttpd-1.4.x)
256 @@ -37,7 +37,7 @@
257         buffer *secret;
258         buffer *uri_prefix;
259  
260 -       unsigned short timeout;
261 +       unsigned int timeout;
262  } plugin_config;
263  
264  typedef struct {
265 @@ -99,7 +99,7 @@
266                 { "secdownload.secret",            NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
267                 { "secdownload.document-root",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
268                 { "secdownload.uri-prefix",        NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 2 */
269 -               { "secdownload.timeout",           NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 3 */
270 +               { "secdownload.timeout",           NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION },        /* 3 */
271                 { NULL,                            NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
272         };
273  
274 @@ -245,8 +245,8 @@
275         }
276  
277         /* timed-out */
278 -       if ( (srv->cur_ts > ts && srv->cur_ts - ts > p->conf.timeout) ||
279 -            (srv->cur_ts < ts && ts - srv->cur_ts > p->conf.timeout) ) {
280 +       if ( (srv->cur_ts > ts && (unsigned int) (srv->cur_ts - ts) > p->conf.timeout) ||
281 +            (srv->cur_ts < ts && (unsigned int) (ts - srv->cur_ts) > p->conf.timeout) ) {
282                 /* "Gone" as the url will never be valid again instead of "408 - Timeout" where the request may be repeated */
283                 con->http_status = 410;
284  
285 Index: src/base.h
286 ===================================================================
287 --- src/base.h  (.../tags/lighttpd-1.4.23)
288 +++ src/base.h  (.../branches/lighttpd-1.4.x)
289 @@ -84,6 +84,7 @@
290  typedef enum { T_CONFIG_UNSET,
291                 T_CONFIG_STRING,
292                 T_CONFIG_SHORT,
293 +               T_CONFIG_INT,
294                 T_CONFIG_BOOLEAN,
295                 T_CONFIG_ARRAY,
296                 T_CONFIG_LOCAL,
297 @@ -281,7 +282,7 @@
298         unsigned short etag_use_mtime;
299         unsigned short etag_use_size;
300         unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
301 -       unsigned short max_request_size;
302 +       unsigned int max_request_size;
303  
304         unsigned short kbytes_per_second; /* connection kb/s limit */
305  
306 @@ -472,6 +473,7 @@
307  
308         buffer *errorlog_file;
309         unsigned short errorlog_use_syslog;
310 +       buffer *breakagelog_file;
311  
312         unsigned short dont_daemonize;
313         buffer *changeroot;
314 @@ -490,7 +492,7 @@
315         unsigned short max_worker;
316         unsigned short max_fds;
317         unsigned short max_conns;
318 -       unsigned short max_request_size;
319 +       unsigned int max_request_size;
320  
321         unsigned short log_request_header_on_error;
322         unsigned short log_state_handling;
323 @@ -538,7 +540,7 @@
324  
325         /* the errorlog */
326         int errorlog_fd;
327 -       enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG, ERRORLOG_PIPE } errorlog_mode;
328 +       enum { ERRORLOG_FILE, ERRORLOG_FD, ERRORLOG_SYSLOG, ERRORLOG_PIPE } errorlog_mode;
329         buffer *errorlog_buf;
330  
331         fdevents *ev, *ev_ins;
332 Index: src/mod_rewrite.c
333 ===================================================================
334 --- src/mod_rewrite.c   (.../tags/lighttpd-1.4.23)
335 +++ src/mod_rewrite.c   (.../branches/lighttpd-1.4.x)
336 @@ -176,7 +176,7 @@
337         data_unset *du;
338  
339         if (NULL != (du = array_get_element(ca, option))) {
340 -               data_array *da = (data_array *)du;
341 +               data_array *da;
342                 size_t j;
343  
344                 if (du->type != TYPE_ARRAY) {
345 @@ -373,7 +373,7 @@
346                         }
347                 } else {
348                         const char **list;
349 -                       size_t start, end;
350 +                       size_t start;
351                         size_t k;
352  
353                         /* it matched */
354 @@ -383,17 +383,15 @@
355  
356                         buffer_reset(con->request.uri);
357  
358 -                       start = 0; end = pattern_len;
359 +                       start = 0;
360                         for (k = 0; k < pattern_len; k++) {
361                                 if (pattern[k] == '$' || pattern[k] == '%') {
362                                         /* got one */
363  
364                                         size_t num = pattern[k + 1] - '0';
365  
366 -                                       end = k;
367 +                                       buffer_append_string_len(con->request.uri, pattern + start, k - start);
368  
369 -                                       buffer_append_string_len(con->request.uri, pattern + start, end - start);
370 -
371                                         if (!isdigit((unsigned char)pattern[k + 1])) {
372                                                 /* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */
373                                                 buffer_append_string_len(con->request.uri, pattern+k, pattern[k] == pattern[k+1] ? 1 : 2);
374 Index: src/connections.c
375 ===================================================================
376 --- src/connections.c   (.../tags/lighttpd-1.4.23)
377 +++ src/connections.c   (.../branches/lighttpd-1.4.x)
378 @@ -782,13 +782,13 @@
379         CLEAN(request.pathinfo);
380         CLEAN(request.request);
381  
382 -       CLEAN(request.orig_uri);
383 +       /* CLEAN(request.orig_uri); */
384  
385         CLEAN(uri.scheme);
386 -       CLEAN(uri.authority);
387 -       CLEAN(uri.path);
388 +       /* CLEAN(uri.authority); */
389 +       /* CLEAN(uri.path); */
390         CLEAN(uri.path_raw);
391 -       CLEAN(uri.query);
392 +       /* CLEAN(uri.query); */
393  
394         CLEAN(physical.doc_root);
395         CLEAN(physical.path);
396 @@ -1401,6 +1401,11 @@
397                                                 "state for fd", con->fd, connection_get_state(con->state));
398                         }
399  
400 +                       buffer_reset(con->uri.authority);
401 +                       buffer_reset(con->uri.path);
402 +                       buffer_reset(con->uri.query);
403 +                       buffer_reset(con->request.orig_uri);
404 +
405                         if (http_request_parse(srv, con)) {
406                                 /* we have to read some data from the POST request */
407  
408 @@ -1725,7 +1730,7 @@
409                                 case HANDLER_FINISHED:
410                                         break;
411                                 default:
412 -                                       log_error_write(srv, __FILE__, __LINE__, "");
413 +                                       log_error_write(srv, __FILE__, __LINE__, "sd", "unhandling return value", r);
414                                         break;
415                                 }
416                                 break;
417 Index: src/network.c
418 ===================================================================
419 --- src/network.c       (.../tags/lighttpd-1.4.23)
420 +++ src/network.c       (.../branches/lighttpd-1.4.x)
421 @@ -90,6 +90,7 @@
422  
423         srv_socket = calloc(1, sizeof(*srv_socket));
424         srv_socket->fd = -1;
425 +       srv_socket->fde_ndx = -1;
426  
427         srv_socket->srv_token = buffer_init();
428         buffer_copy_string_buffer(srv_socket->srv_token, host_token);
429 @@ -103,7 +104,7 @@
430         if (NULL == (sp = strrchr(b->ptr, ':'))) {
431                 log_error_write(srv, __FILE__, __LINE__, "sb", "value of $SERVER[\"socket\"] has to be \"ip:port\".", b);
432  
433 -               return -1;
434 +               goto error_free_socket;
435         }
436  
437         host = b->ptr;
438 @@ -126,7 +127,7 @@
439         } else if (port == 0 || port > 65535) {
440                 log_error_write(srv, __FILE__, __LINE__, "sd", "port out of range:", port);
441  
442 -               return -1;
443 +               goto error_free_socket;
444         }
445  
446         if (*host == '\0') host = NULL;
447 @@ -138,12 +139,12 @@
448  
449                 if (-1 == (srv_socket->fd = socket(srv_socket->addr.plain.sa_family, SOCK_STREAM, 0))) {
450                         log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno));
451 -                       return -1;
452 +                       goto error_free_socket;
453                 }
454  #else
455                 log_error_write(srv, __FILE__, __LINE__, "s",
456                                 "ERROR: Unix Domain sockets are not supported.");
457 -               return -1;
458 +               goto error_free_socket;
459  #endif
460         }
461  
462 @@ -153,7 +154,7 @@
463  
464                 if (-1 == (srv_socket->fd = socket(srv_socket->addr.plain.sa_family, SOCK_STREAM, IPPROTO_TCP))) {
465                         log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno));
466 -                       return -1;
467 +                       goto error_free_socket;
468                 }
469                 srv_socket->use_ipv6 = 1;
470         }
471 @@ -163,17 +164,22 @@
472                 srv_socket->addr.plain.sa_family = AF_INET;
473                 if (-1 == (srv_socket->fd = socket(srv_socket->addr.plain.sa_family, SOCK_STREAM, IPPROTO_TCP))) {
474                         log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno));
475 -                       return -1;
476 +                       goto error_free_socket;
477                 }
478         }
479  
480 +#ifdef FD_CLOEXEC
481 +       /* set FD_CLOEXEC now, fdevent_fcntl_set is called later; needed for pipe-logger forks */
482 +       fcntl(srv_socket->fd, F_SETFD, FD_CLOEXEC);
483 +#endif
484 +
485         /* */
486         srv->cur_fds = srv_socket->fd;
487  
488         val = 1;
489         if (setsockopt(srv_socket->fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
490                 log_error_write(srv, __FILE__, __LINE__, "ss", "socketsockopt failed:", strerror(errno));
491 -               return -1;
492 +               goto error_free_socket;
493         }
494  
495         switch(srv_socket->addr.plain.sa_family) {
496 @@ -198,7 +204,7 @@
497                                                 "sssss", "getaddrinfo failed: ",
498                                                 gai_strerror(r), "'", host, "'");
499  
500 -                               return -1;
501 +                               goto error_free_socket;
502                         }
503  
504                         memcpy(&(srv_socket->addr), res->ai_addr, res->ai_addrlen);
505 @@ -220,17 +226,17 @@
506                                 log_error_write(srv, __FILE__, __LINE__,
507                                                 "sds", "gethostbyname failed: ",
508                                                 h_errno, host);
509 -                               return -1;
510 +                               goto error_free_socket;
511                         }
512  
513                         if (he->h_addrtype != AF_INET) {
514                                 log_error_write(srv, __FILE__, __LINE__, "sd", "addr-type != AF_INET: ", he->h_addrtype);
515 -                               return -1;
516 +                               goto error_free_socket;
517                         }
518  
519                         if (he->h_length != sizeof(struct in_addr)) {
520                                 log_error_write(srv, __FILE__, __LINE__, "sd", "addr-length != sizeof(in_addr): ", he->h_length);
521 -                               return -1;
522 +                               goto error_free_socket;
523                         }
524  
525                         memcpy(&(srv_socket->addr.ipv4.sin_addr.s_addr), he->h_addr_list[0], he->h_length);
526 @@ -260,7 +266,7 @@
527                                 host);
528  
529  
530 -                       return -1;
531 +                       goto error_free_socket;
532                 }
533  
534                 /* connect failed */
535 @@ -275,14 +281,12 @@
536                                 "testing socket failed:",
537                                 host, strerror(errno));
538  
539 -                       return -1;
540 +                       goto error_free_socket;
541                 }
542  
543                 break;
544         default:
545 -               addr_len = 0;
546 -
547 -               return -1;
548 +               goto error_free_socket;
549         }
550  
551         if (0 != bind(srv_socket->fd, (struct sockaddr *) &(srv_socket->addr), addr_len)) {
552 @@ -298,12 +302,12 @@
553                                         host, port, strerror(errno));
554                         break;
555                 }
556 -               return -1;
557 +               goto error_free_socket;
558         }
559  
560         if (-1 == listen(srv_socket->fd, 128 * 8)) {
561                 log_error_write(srv, __FILE__, __LINE__, "ss", "listen failed: ", strerror(errno));
562 -               return -1;
563 +               goto error_free_socket;
564         }
565  
566         if (s->is_ssl) {
567 @@ -316,14 +320,14 @@
568                         if (0 == RAND_status()) {
569                                 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
570                                                 "not enough entropy in the pool");
571 -                               return -1;
572 +                               goto error_free_socket;
573                         }
574                 }
575  
576                 if (NULL == (s->ssl_ctx = SSL_CTX_new(SSLv23_server_method()))) {
577                         log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
578                                         ERR_error_string(ERR_get_error(), NULL));
579 -                       return -1;
580 +                       goto error_free_socket;
581                 }
582  
583                 if (!s->ssl_use_sslv2) {
584 @@ -331,7 +335,7 @@
585                         if (SSL_OP_NO_SSLv2 != SSL_CTX_set_options(s->ssl_ctx, SSL_OP_NO_SSLv2)) {
586                                 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
587                                                 ERR_error_string(ERR_get_error(), NULL));
588 -                               return -1;
589 +                               goto error_free_socket;
590                         }
591                 }
592  
593 @@ -340,33 +344,33 @@
594                         if (SSL_CTX_set_cipher_list(s->ssl_ctx, s->ssl_cipher_list->ptr) != 1) {
595                                 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
596                                                 ERR_error_string(ERR_get_error(), NULL));
597 -                               return -1;
598 +                               goto error_free_socket;
599                         }
600                 }
601  
602                 if (buffer_is_empty(s->ssl_pemfile)) {
603                         log_error_write(srv, __FILE__, __LINE__, "s", "ssl.pemfile has to be set");
604 -                       return -1;
605 +                       goto error_free_socket;
606                 }
607  
608                 if (!buffer_is_empty(s->ssl_ca_file)) {
609                         if (1 != SSL_CTX_load_verify_locations(s->ssl_ctx, s->ssl_ca_file->ptr, NULL)) {
610                                 log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:",
611                                                 ERR_error_string(ERR_get_error(), NULL), s->ssl_ca_file);
612 -                               return -1;
613 +                               goto error_free_socket;
614                         }
615                 }
616  
617                 if (SSL_CTX_use_certificate_file(s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {
618                         log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:",
619                                         ERR_error_string(ERR_get_error(), NULL), s->ssl_pemfile);
620 -                       return -1;
621 +                       goto error_free_socket;
622                 }
623  
624                 if (SSL_CTX_use_PrivateKey_file (s->ssl_ctx, s->ssl_pemfile->ptr, SSL_FILETYPE_PEM) < 0) {
625                         log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:",
626                                         ERR_error_string(ERR_get_error(), NULL), s->ssl_pemfile);
627 -                       return -1;
628 +                       goto error_free_socket;
629                 }
630  
631                 if (SSL_CTX_check_private_key(s->ssl_ctx) != 1) {
632 @@ -374,7 +378,7 @@
633                                         "Private key does not match the certificate public key, reason:",
634                                         ERR_error_string(ERR_get_error(), NULL),
635                                         s->ssl_pemfile);
636 -                       return -1;
637 +                       goto error_free_socket;
638                 }
639                 SSL_CTX_set_default_read_ahead(s->ssl_ctx, 1);
640                 SSL_CTX_set_mode(s->ssl_ctx, SSL_CTX_get_mode(s->ssl_ctx) | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
641 @@ -390,7 +394,7 @@
642                 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
643                                 "ssl requested but openssl support is not compiled in");
644  
645 -               return -1;
646 +               goto error_free_socket;
647  #endif
648  #ifdef TCP_DEFER_ACCEPT
649         } else if (s->defer_accept) {
650 @@ -414,7 +418,6 @@
651         }
652  
653         srv_socket->is_ssl = s->is_ssl;
654 -       srv_socket->fde_ndx = -1;
655  
656         if (srv->srv_sockets.size == 0) {
657                 srv->srv_sockets.size = 4;
658 @@ -430,6 +433,21 @@
659         buffer_free(b);
660  
661         return 0;
662 +
663 +error_free_socket:
664 +       if (srv_socket->fd != -1) {
665 +               /* check if server fd are already registered */
666 +               if (srv_socket->fde_ndx != -1) {
667 +                       fdevent_event_del(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd);
668 +                       fdevent_unregister(srv->ev, srv_socket->fd);
669 +               }
670 +
671 +               close(srv_socket->fd);
672 +       }
673 +       buffer_free(srv_socket->srv_token);
674 +       free(srv_socket);
675 +
676 +       return -1;
677  }
678  
679  int network_close(server *srv) {
680 @@ -567,12 +585,8 @@
681                 /* not our stage */
682                 if (COMP_SERVER_SOCKET != dc->comp) continue;
683  
684 -               if (dc->cond != CONFIG_COND_EQ) {
685 -                       log_error_write(srv, __FILE__, __LINE__, "s", "only == is allowed for $SERVER[\"socket\"].");
686 +               if (dc->cond != CONFIG_COND_EQ) continue;
687  
688 -                       return -1;
689 -               }
690 -
691                 /* check if we already know this socket,
692                  * if yes, don't init it */
693                 for (j = 0; j < srv->srv_sockets.used; j++) {
694 Index: src/configfile.c
695 ===================================================================
696 --- src/configfile.c    (.../tags/lighttpd-1.4.23)
697 +++ src/configfile.c    (.../branches/lighttpd-1.4.x)
698 @@ -42,12 +42,12 @@
699  
700                 { "server.event-handler",        NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 10 */
701                 { "server.pid-file",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 11 */
702 -               { "server.max-request-size",     NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 12 */
703 +               { "server.max-request-size",     NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION },     /* 12 */
704                 { "server.max-worker",           NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER },       /* 13 */
705                 { "server.document-root",        NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 14 */
706 -               { "server.force-lowercase-filenames", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },   /* 15 */
707 +               { "server.force-lowercase-filenames", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },/* 15 */
708                 { "debug.log-condition-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },    /* 16 */
709 -               { "server.max-keep-alive-requests", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 17 */
710 +               { "server.max-keep-alive-requests", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },/* 17 */
711                 { "server.name",                 NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 18 */
712                 { "server.max-keep-alive-idle",  NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 19 */
713  
714 @@ -91,12 +91,13 @@
715                 { "server.core-files",           NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 46 */
716                 { "ssl.cipher-list",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 47 */
717                 { "ssl.use-sslv2",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 48 */
718 -               { "etag.use-inode",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */
719 -               { "etag.use-mtime",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */
720 -               { "etag.use-size",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 51 */
721 +               { "etag.use-inode",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 49 */
722 +               { "etag.use-mtime",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 50 */
723 +               { "etag.use-size",               NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER },     /* 51 */
724                 { "server.reject-expect-100-with-417",  NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 52 */
725                 { "debug.log-timeouts",          NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 53 */
726 -               { "server.defer-accept",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },     /* 54 */
727 +               { "server.defer-accept",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 54 */
728 +               { "server.breakagelog",          NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },      /* 55 */
729                 { "server.host",                 "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
730                 { "server.docroot",              "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
731                 { "server.virtual-root",         "load mod_simple_vhost and use simple-vhost.server-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
732 @@ -139,6 +140,8 @@
733         cv[43].destination = &(srv->srvconf.max_conns);
734         cv[12].destination = &(srv->srvconf.max_request_size);
735         cv[52].destination = &(srv->srvconf.reject_expect_100_with_417);
736 +       cv[55].destination = srv->srvconf.breakagelog_file;
737 +
738         srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
739  
740         assert(srv->config_storage);
741 @@ -290,6 +293,7 @@
742         PATCH(log_condition_handling);
743         PATCH(log_file_not_found);
744         PATCH(log_ssl_noise);
745 +       PATCH(log_timeouts);
746  
747         PATCH(range_requests);
748         PATCH(force_lowercase_filenames);
749 @@ -1135,15 +1139,15 @@
750                  * - select works everywhere
751                  * - linux-* are experimental
752                  */
753 +#ifdef USE_LINUX_EPOLL
754 +               { FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
755 +#endif
756  #ifdef USE_POLL
757                 { FDEVENT_HANDLER_POLL,           "poll" },
758  #endif
759  #ifdef USE_SELECT
760                 { FDEVENT_HANDLER_SELECT,         "select" },
761  #endif
762 -#ifdef USE_LINUX_EPOLL
763 -               { FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
764 -#endif
765  #ifdef USE_LINUX_SIGIO
766                 { FDEVENT_HANDLER_LINUX_RTSIG,    "linux-rtsig" },
767  #endif
768 Index: src/mod_evhost.c
769 ===================================================================
770 --- src/mod_evhost.c    (.../tags/lighttpd-1.4.23)
771 +++ src/mod_evhost.c    (.../branches/lighttpd-1.4.x)
772 @@ -213,7 +213,7 @@
773                 if (colon != ptr) {
774                         ds = data_string_init();
775                         buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
776 -                       buffer_append_long(ds->key, i++);
777 +                       buffer_append_long(ds->key, i /* ++ */);
778                         buffer_copy_string_len(ds->value,ptr,colon-ptr);
779  
780                         array_insert_unique(host,(data_unset *)ds);
781 @@ -294,10 +294,10 @@
782                                 char *colon = strchr(con->uri.authority->ptr, ':');
783  
784                                 if(colon == NULL) {
785 -                                       buffer_append_string_buffer(p->tmp_buf, con->uri.authority); // adds fqdn
786 +                                       buffer_append_string_buffer(p->tmp_buf, con->uri.authority); /* adds fqdn */
787                                 } else {
788                                         /* strip the port out of the authority-part of the URI scheme */
789 -                                       buffer_append_string_len(p->tmp_buf, con->uri.authority->ptr, colon - con->uri.authority->ptr); // adds fqdn
790 +                                       buffer_append_string_len(p->tmp_buf, con->uri.authority->ptr, colon - con->uri.authority->ptr); /* adds fqdn */
791                                 }
792                         } else if (NULL != (ds = (data_string *)array_get_element(parsed_host,p->conf.path_pieces[i]->ptr))) {
793                                 if (ds->value->used) {
794 Index: src/splaytree.c
795 ===================================================================
796 --- src/splaytree.c     (.../tags/lighttpd-1.4.23)
797 +++ src/splaytree.c     (.../branches/lighttpd-1.4.x)
798 @@ -61,12 +61,11 @@
799   * size fields are maintained */
800  splay_tree * splaytree_splay (splay_tree *t, int i) {
801      splay_tree N, *l, *r, *y;
802 -    int comp, root_size, l_size, r_size;
803 +    int comp, l_size, r_size;
804  
805      if (t == NULL) return t;
806      N.left = N.right = NULL;
807      l = r = &N;
808 -    root_size = node_size(t);
809      l_size = r_size = 0;
810  
811      for (;;) {
812 Index: src/lemon.c
813 ===================================================================
814 --- src/lemon.c (.../tags/lighttpd-1.4.23)
815 +++ src/lemon.c (.../branches/lighttpd-1.4.x)
816 @@ -39,6 +39,12 @@
817  #   endif
818  #endif
819  
820 +#if __GNUC__ > 2
821 +#define NORETURN __attribute__ ((__noreturn__))
822 +#else
823 +#define NORETURN
824 +#endif
825 +
826  /* #define PRIVATE static */
827  #define PRIVATE static
828  
829 @@ -51,7 +57,7 @@
830  char *msort();
831  extern void *malloc();
832  
833 -extern void memory_error();
834 +extern void memory_error() NORETURN;
835  
836  /******** From the file "action.h" *************************************/
837  struct action *Action_new();
838 @@ -59,7 +65,7 @@
839  void Action_add();
840  
841  /********* From the file "assert.h" ************************************/
842 -void myassert();
843 +void myassert() NORETURN;
844  #ifndef NDEBUG
845  #  define assert(X) if(!(X))myassert(__FILE__,__LINE__)
846  #else
847 @@ -1333,7 +1339,7 @@
848  /* Report an out-of-memory condition and abort.  This function
849  ** is used mostly by the "MemoryCheck" macro in struct.h
850  */
851 -void memory_error(){
852 +void memory_error() {
853    fprintf(stderr,"Out of memory.  Aborting...\n");
854    exit(1);
855  }
856 @@ -1608,7 +1614,6 @@
857  FILE *err;
858  {
859    int spcnt, i;
860 -  spcnt = 0;
861    if( argv[0] ) fprintf(err,"%s",argv[0]);
862    spcnt = strlen(argv[0]) + 1;
863    for(i=1; i<n && argv[i]; i++){
864 @@ -2336,6 +2341,7 @@
865    if( filebuf==0 ){
866      ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.",
867        filesize+1);
868 +    fclose(fp);
869      gp->errorcnt++;
870      return;
871    }
872 @@ -2343,6 +2349,7 @@
873      ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.",
874        filesize);
875      free(filebuf);
876 +    fclose(fp);
877      gp->errorcnt++;
878      return;
879    }
880 @@ -2913,7 +2920,7 @@
881   }else if( sp->destructor ){
882     cp = sp->destructor;
883     fprintf(out,"#line %d \"%s\"\n{",sp->destructorln,lemp->filename);
884 - }else if( lemp->vardest ){
885 + }else{
886     cp = lemp->vardest;
887     if( cp==0 ) return;
888     fprintf(out,"#line %d \"%s\"\n{",lemp->vardestln,lemp->filename);
889 @@ -3042,7 +3049,7 @@
890  int *plineno;               /* Pointer to the line number */
891  int mhflag;                 /* True if generating makeheaders output */
892  {
893 -  int lineno = *plineno;    /* The line number of the output */
894 +  int lineno;               /* The line number of the output */
895    char **types;             /* A hash table of datatypes */
896    int arraysize;            /* Size of the "types" array */
897    int maxdtlength;          /* Maximum length of any ".datatype" field. */
898 Index: src/mod_scgi.c
899 ===================================================================
900 --- src/mod_scgi.c      (.../tags/lighttpd-1.4.23)
901 +++ src/mod_scgi.c      (.../branches/lighttpd-1.4.x)
902 @@ -331,8 +331,21 @@
903  
904  int scgi_proclist_sort_down(server *srv, scgi_extension_host *host, scgi_proc *proc);
905  
906 +static void reset_signals(void) {
907 +#ifdef SIGTTOU
908 +       signal(SIGTTOU, SIG_DFL);
909 +#endif
910 +#ifdef SIGTTIN
911 +       signal(SIGTTIN, SIG_DFL);
912 +#endif
913 +#ifdef SIGTSTP
914 +       signal(SIGTSTP, SIG_DFL);
915 +#endif
916 +       signal(SIGHUP, SIG_DFL);
917 +       signal(SIGPIPE, SIG_DFL);
918 +       signal(SIGUSR1, SIG_DFL);
919 +}
920  
921 -
922  static handler_ctx * handler_ctx_init() {
923         handler_ctx * hctx;
924  
925 @@ -772,10 +785,8 @@
926                         env.used = 0;
927  
928                         if (scgi_fd != 0) {
929 -                               close(0);
930                                 dup2(scgi_fd, 0);
931                                 close(scgi_fd);
932 -                               scgi_fd = 0;
933                         }
934  
935                         /* we don't need the client socket */
936 @@ -783,8 +794,6 @@
937                                 close(fd);
938                         }
939  
940 -                       openDevNull(STDERR_FILENO);
941 -
942                         /* build clean environment */
943                         if (host->bin_env_copy->used) {
944                                 for (i = 0; i < host->bin_env_copy->used; i++) {
945 @@ -828,6 +837,8 @@
946                         buffer_copy_string_len(b, CONST_STR_LEN("exec "));
947                         buffer_append_string_buffer(b, host->bin_path);
948  
949 +                       reset_signals();
950 +
951                         /* exec the cgi */
952                         execle("/bin/sh", "sh", "-c", b->ptr, (char *)NULL, env.ptr);
953  
954 @@ -2163,8 +2174,11 @@
955         int ret;
956  
957         /* sanity check */
958 -       if (!host ||
959 -           ((!host->host->used || !host->port) && !host->unixsocket->used)) {
960 +       if (!host) {
961 +               log_error_write(srv, __FILE__, __LINE__, "s", "fatal error: host = NULL");
962 +               return HANDLER_ERROR;
963 +       }
964 +       if (((!host->host->used || !host->port) && !host->unixsocket->used)) {
965                 log_error_write(srv, __FILE__, __LINE__, "sxddd",
966                                 "write-req: error",
967                                 host,
968 @@ -2299,8 +2313,8 @@
969  
970                 chunkqueue_remove_finished_chunks(hctx->wb);
971  
972 -               if (-1 == ret) {
973 -                       if (errno == ENOTCONN) {
974 +               if (ret < 0) {
975 +                       if (errno == ENOTCONN || ret == -2) {
976                                 /* the connection got dropped after accept()
977                                  *
978                                  * this is most of the time a PHP which dies
979 @@ -2325,24 +2339,17 @@
980                                  */
981  
982                                 log_error_write(srv, __FILE__, __LINE__, "ssosd",
983 -                                               "[REPORT ME] connection was dropped after accept(). reconnect() denied:",
984 +                                               "connection was dropped after accept(). reconnect() denied:",
985                                                 "write-offset:", hctx->wb->bytes_out,
986                                                 "reconnect attempts:", hctx->reconnects);
987  
988                                 return HANDLER_ERROR;
989 -                       }
990 -
991 -                       if ((errno != EAGAIN) &&
992 -                           (errno != EINTR)) {
993 -
994 +                       } else {
995 +                               /* -1 == ret => error on our side */
996                                 log_error_write(srv, __FILE__, __LINE__, "ssd",
997 -                                               "write failed:", strerror(errno), errno);
998 +                                       "write failed:", strerror(errno), errno);
999  
1000                                 return HANDLER_ERROR;
1001 -                       } else {
1002 -                               fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
1003 -
1004 -                               return HANDLER_WAIT_FOR_EVENT;
1005                         }
1006                 }
1007  
1008 @@ -2469,12 +2476,10 @@
1009  }
1010  
1011  static handler_t scgi_connection_close(server *srv, handler_ctx *hctx) {
1012 -       plugin_data *p;
1013         connection  *con;
1014  
1015         if (NULL == hctx) return HANDLER_GO_ON;
1016  
1017 -       p    = hctx->plugin_data;
1018         con  = hctx->remote_conn;
1019  
1020         log_error_write(srv, __FILE__, __LINE__, "ssdsd",
1021 @@ -2724,27 +2729,29 @@
1022         /* check if extension matches */
1023         for (k = 0; k < p->conf.exts->used; k++) {
1024                 size_t ct_len;
1025 +               scgi_extension *ext = p->conf.exts->exts[k];
1026  
1027 -               extension = p->conf.exts->exts[k];
1028 +               if (ext->key->used == 0) continue;
1029  
1030 -               if (extension->key->used == 0) continue;
1031 +               ct_len = ext->key->used - 1;
1032  
1033 -               ct_len = extension->key->used - 1;
1034 -
1035                 if (s_len < ct_len) continue;
1036  
1037                 /* check extension in the form "/scgi_pattern" */
1038 -               if (*(extension->key->ptr) == '/') {
1039 -                       if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0)
1040 +               if (*(ext->key->ptr) == '/') {
1041 +                       if (strncmp(fn->ptr, ext->key->ptr, ct_len) == 0) {
1042 +                               extension = ext;
1043                                 break;
1044 -               } else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
1045 +                       }
1046 +               } else if (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len)) {
1047                         /* check extension in the form ".fcg" */
1048 +                       extension = ext;
1049                         break;
1050                 }
1051         }
1052  
1053         /* extension doesn't match */
1054 -       if (k == p->conf.exts->used) {
1055 +       if (NULL == extension) {
1056                 return HANDLER_GO_ON;
1057         }
1058  
1059 Index: src/mod_mysql_vhost.c
1060 ===================================================================
1061 --- src/mod_mysql_vhost.c       (.../tags/lighttpd-1.4.23)
1062 +++ src/mod_mysql_vhost.c       (.../branches/lighttpd-1.4.x)
1063 @@ -259,8 +259,14 @@
1064  
1065  #define FOO(x) (s->x->used ? s->x->ptr : NULL)
1066  
1067 +#if MYSQL_VERSION_ID >= 40100
1068 +                        /* CLIENT_MULTI_STATEMENTS first appeared in 4.1 */ 
1069                         if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),
1070 +                                               FOO(mydb), s->port, FOO(mysock), CLIENT_MULTI_STATEMENTS)) {
1071 +#else
1072 +                       if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),
1073                                                 FOO(mydb), s->port, FOO(mysock), 0)) {
1074 +#endif
1075                                 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
1076  
1077                                 return HANDLER_ERROR;
1078 @@ -369,6 +375,9 @@
1079         if (!row || cols < 1) {
1080                 /* no such virtual host */
1081                 mysql_free_result(result);
1082 +#if MYSQL_VERSION_ID >= 40100
1083 +               while (mysql_next_result(p->conf.mysql) == 0);
1084 +#endif
1085                 return HANDLER_GO_ON;
1086         }
1087  
1088 @@ -402,6 +411,9 @@
1089                 c->fcgi_offset = c->fcgi_arg->used = 0;
1090         }
1091         mysql_free_result(result);
1092 +#if MYSQL_VERSION_ID >= 40100
1093 +       while (mysql_next_result(p->conf.mysql) == 0);
1094 +#endif
1095  
1096         /* fix virtual server and docroot */
1097  GO_ON: buffer_copy_string_buffer(con->server_name, c->server_name);
1098 @@ -416,6 +428,9 @@
1099         return HANDLER_GO_ON;
1100  
1101  ERR500:        if (result) mysql_free_result(result);
1102 +#if MYSQL_VERSION_ID >= 40100
1103 +       while (mysql_next_result(p->conf.mysql) == 0);
1104 +#endif
1105         con->http_status = 500; /* Internal Error */
1106         con->mode = DIRECT;
1107         return HANDLER_FINISHED;
1108 @@ -424,15 +439,15 @@
1109  /* this function is called at dlopen() time and inits the callbacks */
1110  int mod_mysql_vhost_plugin_init(plugin *p);
1111  int mod_mysql_vhost_plugin_init(plugin *p) {
1112 -       p->version     = LIGHTTPD_VERSION_ID;
1113 -       p->name                         = buffer_init_string("mysql_vhost");
1114 +       p->version        = LIGHTTPD_VERSION_ID;
1115 +       p->name           = buffer_init_string("mysql_vhost");
1116  
1117 -       p->init                         = mod_mysql_vhost_init;
1118 -       p->cleanup                      = mod_mysql_vhost_cleanup;
1119 -       p->handle_request_done          = mod_mysql_vhost_handle_connection_close;
1120 +       p->init           = mod_mysql_vhost_init;
1121 +       p->cleanup        = mod_mysql_vhost_cleanup;
1122 +       p->connection_reset = mod_mysql_vhost_handle_connection_close;
1123  
1124 -       p->set_defaults                 = mod_mysql_vhost_set_defaults;
1125 -       p->handle_docroot               = mod_mysql_vhost_handle_docroot;
1126 +       p->set_defaults   = mod_mysql_vhost_set_defaults;
1127 +       p->handle_docroot = mod_mysql_vhost_handle_docroot;
1128  
1129         return 0;
1130  }
1131 @@ -441,7 +456,7 @@
1132  int mod_mysql_vhost_plugin_init(plugin *p);
1133  int mod_mysql_vhost_plugin_init(plugin *p) {
1134         p->version     = LIGHTTPD_VERSION_ID;
1135 -       p->name                         = buffer_init_string("mysql_vhost");
1136 +       p->name        = buffer_init_string("mysql_vhost");
1137  
1138         return 0;
1139  }
1140 Index: src/request.c
1141 ===================================================================
1142 --- src/request.c       (.../tags/lighttpd-1.4.23)
1143 +++ src/request.c       (.../branches/lighttpd-1.4.x)
1144 @@ -111,7 +111,7 @@
1145  
1146                                         /* check the first character at right of the dot */
1147                                         if (is_ip == 0) {
1148 -                                               if (!light_isalpha(host->ptr[i+1])) {
1149 +                                               if (!light_isalnum(host->ptr[i+1])) {
1150                                                         return -1;
1151                                                 }
1152                                         } else if (!light_isdigit(host->ptr[i+1])) {
1153 @@ -133,7 +133,7 @@
1154                                 }
1155                         } else if (i == 0) {
1156                                 /* the first character of the hostname */
1157 -                               if (!light_isalpha(c)) {
1158 +                               if (!light_isalnum(c)) {
1159                                         return -1;
1160                                 }
1161                                 label_len++;
1162 @@ -540,8 +540,8 @@
1163                 con->response.keep_alive = 0;
1164                 con->keep_alive = 0;
1165  
1166 -               log_error_write(srv, __FILE__, __LINE__, "s", "no uri specified -> 400");
1167                 if (srv->srvconf.log_request_header_on_error) {
1168 +                       log_error_write(srv, __FILE__, __LINE__, "s", "no uri specified -> 400");
1169                         log_error_write(srv, __FILE__, __LINE__, "Sb",
1170                                                         "request-header:\n",
1171                                                         con->request.request);
1172 Index: src/network_backends.h
1173 ===================================================================
1174 --- src/network_backends.h      (.../tags/lighttpd-1.4.23)
1175 +++ src/network_backends.h      (.../branches/lighttpd-1.4.x)
1176 @@ -45,6 +45,11 @@
1177  
1178  #include "base.h"
1179  
1180 +/* return values:
1181 + * >= 0 : chunks completed
1182 + *   -1 : error (on our side)
1183 + *   -2 : remote close
1184 + */
1185  
1186  int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq);
1187  int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq);
1188 Index: src/mod_rrdtool.c
1189 ===================================================================
1190 --- src/mod_rrdtool.c   (.../tags/lighttpd-1.4.23)
1191 +++ src/mod_rrdtool.c   (.../branches/lighttpd-1.4.x)
1192 @@ -139,10 +139,8 @@
1193  
1194                 args[i++] = p->conf.path_rrdtool_bin->ptr;
1195                 args[i++] = dash;
1196 -               args[i++] = NULL;
1197 +               args[i  ] = NULL;
1198  
1199 -               openDevNull(STDERR_FILENO);
1200 -
1201                 /* we don't need the client socket */
1202                 for (i = 3; i < 256; i++) {
1203                         close(i);
1204 @@ -268,7 +266,7 @@
1205                 "RRA:MIN:0.5:24:775 "
1206                 "RRA:MIN:0.5:288:797\n"));
1207  
1208 -       if (-1 == (r = safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
1209 +       if (-1 == (safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
1210                 log_error_write(srv, __FILE__, __LINE__, "ss",
1211                         "rrdtool-write: failed", strerror(errno));
1212  
1213 Index: src/stat_cache.c
1214 ===================================================================
1215 --- src/stat_cache.c    (.../tags/lighttpd-1.4.23)
1216 +++ src/stat_cache.c    (.../branches/lighttpd-1.4.x)
1217 @@ -503,12 +503,10 @@
1218         }
1219  
1220         if (NULL == sce) {
1221 -               int osize = 0;
1222 +#ifdef DEBUG_STAT_CACHE
1223 +               int osize = splaytree_size(sc->files);
1224 +#endif
1225  
1226 -               if (sc->files) {
1227 -                       osize = sc->files->size;
1228 -               }
1229 -
1230                 sce = stat_cache_entry_init();
1231                 buffer_copy_string_buffer(sce->name, name);
1232  
1233 Index: src/response.h
1234 ===================================================================
1235 --- src/response.h      (.../tags/lighttpd-1.4.23)
1236 +++ src/response.h      (.../branches/lighttpd-1.4.x)
1237 @@ -10,6 +10,7 @@
1238  
1239  int response_header_insert(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen);
1240  int response_header_overwrite(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen);
1241 +int response_header_append(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen);
1242  
1243  handler_t http_response_prepare(server *srv, connection *con);
1244  int http_response_redirect_to_directory(server *srv, connection *con);
1245 Index: src/mod_proxy.c
1246 ===================================================================
1247 --- src/mod_proxy.c     (.../tags/lighttpd-1.4.23)
1248 +++ src/mod_proxy.c     (.../branches/lighttpd-1.4.x)
1249 @@ -756,12 +756,15 @@
1250  
1251         switch(hctx->state) {
1252         case PROXY_STATE_INIT:
1253 +#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
1254                 if (strstr(host->host->ptr,":")) {
1255                     if (-1 == (hctx->fd = socket(AF_INET6, SOCK_STREAM, 0))) {
1256                         log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno));
1257                         return HANDLER_ERROR;
1258                     }
1259 -               } else {
1260 +               } else
1261 +#endif
1262 +               {
1263                     if (-1 == (hctx->fd = socket(AF_INET, SOCK_STREAM, 0))) {
1264                         log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno));
1265                         return HANDLER_ERROR;
1266 @@ -842,17 +845,14 @@
1267  
1268                 chunkqueue_remove_finished_chunks(hctx->wb);
1269  
1270 -               if (-1 == ret) {
1271 -                       if (errno != EAGAIN &&
1272 -                           errno != EINTR) {
1273 -                               log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
1274 +               if (-1 == ret) { /* error on our side */
1275 +                       log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
1276  
1277 -                               return HANDLER_ERROR;
1278 -                       } else {
1279 -                               fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
1280 +                       return HANDLER_WAIT_FOR_EVENT;
1281 +               } else if (-2 == ret) { /* remote close */
1282 +                       log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed, remote connection close:", strerror(errno), errno);
1283  
1284 -                               return HANDLER_WAIT_FOR_EVENT;
1285 -                       }
1286 +                       return HANDLER_WAIT_FOR_EVENT;
1287                 }
1288  
1289                 if (hctx->wb->bytes_out == hctx->wb->bytes_in) {
1290 @@ -1107,19 +1107,20 @@
1291  
1292         /* check if extension matches */
1293         for (k = 0; k < p->conf.extensions->used; k++) {
1294 +               data_array *ext = NULL;
1295                 size_t ct_len;
1296  
1297 -               extension = (data_array *)p->conf.extensions->data[k];
1298 +               ext = (data_array *)p->conf.extensions->data[k];
1299  
1300 -               if (extension->key->used == 0) continue;
1301 +               if (ext->key->used == 0) continue;
1302  
1303 -               ct_len = extension->key->used - 1;
1304 +               ct_len = ext->key->used - 1;
1305  
1306                 if (s_len < ct_len) continue;
1307  
1308                 /* check extension in the form "/proxy_pattern" */
1309 -               if (*(extension->key->ptr) == '/') {
1310 -                       if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0) {
1311 +               if (*(ext->key->ptr) == '/') {
1312 +                       if (strncmp(fn->ptr, ext->key->ptr, ct_len) == 0) {
1313                                 if (s_len > ct_len + 1) {
1314                                         char *pi_offset;
1315  
1316 @@ -1127,15 +1128,17 @@
1317                                                 path_info_offset = pi_offset - fn->ptr;
1318                                         }
1319                                 }
1320 +                               extension = ext;
1321                                 break;
1322                         }
1323 -               } else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
1324 +               } else if (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len)) {
1325                         /* check extension in the form ".fcg" */
1326 +                       extension = ext;
1327                         break;
1328                 }
1329         }
1330  
1331 -       if (k == p->conf.extensions->used) {
1332 +       if (NULL == extension) {
1333                 return HANDLER_GO_ON;
1334         }
1335  
1336 Index: src/Makefile.am
1337 ===================================================================
1338 --- src/Makefile.am     (.../tags/lighttpd-1.4.23)
1339 +++ src/Makefile.am     (.../branches/lighttpd-1.4.x)
1340 @@ -13,14 +13,14 @@
1341  versionstamp:
1342         @test -f versionstamp.h || touch versionstamp.h; \
1343         REVISION=""; \
1344 -       if test -x "`which svnversion`"; then \
1345 -               REVISION="$$(LANG=C svnversion "$(top_srcdir)" 2>/dev/null || echo exported)"; \
1346 +       if test -d "$(top_srcdir)/.svn" -a -x "`which svnversion`"; then \
1347 +               REVISION="$$(LANG= LC_ALL=C svnversion "$(top_srcdir)" 2>/dev/null || echo exported)"; \
1348                 if test "$$REVISION" = "exported"; then \
1349                         REVISION=""; \
1350                 fi; \
1351         fi; \
1352         if test -z "$$REVISION" -a -x "`which git`"; then \
1353 -               REVISION="$$(cd "$(top_srcdir)"; LANG=C git describe --always 2>/dev/null || echo)"; \
1354 +               REVISION="$$(cd "$(top_srcdir)"; LANG= LC_ALL=C git describe --always 2>/dev/null || echo)"; \
1355         fi; \
1356         if test -n "$$REVISION"; then \
1357                 echo "#define REPO_VERSION \"-devel-$$REVISION\"" > versionstamp.h.tmp; \
1358 Index: src/mod_expire.c
1359 ===================================================================
1360 --- src/mod_expire.c    (.../tags/lighttpd-1.4.23)
1361 +++ src/mod_expire.c    (.../branches/lighttpd-1.4.x)
1362 @@ -342,7 +342,7 @@
1363                         buffer_copy_string_len(p->expire_tstmp, CONST_STR_LEN("max-age="));
1364                         buffer_append_long(p->expire_tstmp, expires - srv->cur_ts); /* as expires >= srv->cur_ts the difference is >= 0 */
1365  
1366 -                       response_header_overwrite(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp));
1367 +                       response_header_append(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp));
1368  
1369                         return HANDLER_GO_ON;
1370                 }
1371 Index: src/http_auth.c
1372 ===================================================================
1373 --- src/http_auth.c     (.../tags/lighttpd-1.4.23)
1374 +++ src/http_auth.c     (.../branches/lighttpd-1.4.x)
1375 @@ -918,15 +918,15 @@
1376         char a1[256];
1377         char a2[256];
1378  
1379 -       char *username;
1380 -       char *realm;
1381 -       char *nonce;
1382 -       char *uri;
1383 -       char *algorithm;
1384 -       char *qop;
1385 -       char *cnonce;
1386 -       char *nc;
1387 -       char *respons;
1388 +       char *username = NULL;
1389 +       char *realm = NULL;
1390 +       char *nonce = NULL;
1391 +       char *uri = NULL;
1392 +       char *algorithm = NULL;
1393 +       char *qop = NULL;
1394 +       char *cnonce = NULL;
1395 +       char *nc = NULL;
1396 +       char *respons = NULL;
1397  
1398         char *e, *c;
1399         const char *m = NULL;
1400 @@ -967,15 +967,9 @@
1401         dkv[6].ptr = &cnonce;
1402         dkv[7].ptr = &nc;
1403         dkv[8].ptr = &respons;
1404 -       dkv[9].ptr = NULL;
1405  
1406         UNUSED(req);
1407  
1408 -       for (i = 0; dkv[i].key; i++) {
1409 -               *(dkv[i].ptr) = NULL;
1410 -       }
1411 -
1412 -
1413         if (p->conf.auth_backend != AUTH_BACKEND_HTDIGEST &&
1414             p->conf.auth_backend != AUTH_BACKEND_PLAIN) {
1415                 log_error_write(srv, __FILE__, __LINE__, "s",
1416 Index: src/mod_redirect.c
1417 ===================================================================
1418 --- src/mod_redirect.c  (.../tags/lighttpd-1.4.23)
1419 +++ src/mod_redirect.c  (.../branches/lighttpd-1.4.x)
1420 @@ -203,7 +203,7 @@
1421                         }
1422                 } else {
1423                         const char **list;
1424 -                       size_t start, end;
1425 +                       size_t start;
1426                         size_t k;
1427  
1428                         /* it matched */
1429 @@ -213,17 +213,15 @@
1430  
1431                         buffer_reset(p->location);
1432  
1433 -                       start = 0; end = pattern_len;
1434 +                       start = 0;
1435                         for (k = 0; k < pattern_len; k++) {
1436                                 if (pattern[k] == '$' || pattern[k] == '%') {
1437                                         /* got one */
1438  
1439                                         size_t num = pattern[k + 1] - '0';
1440  
1441 -                                       end = k;
1442 +                                       buffer_append_string_len(p->location, pattern + start, k - start);
1443  
1444 -                                       buffer_append_string_len(p->location, pattern + start, end - start);
1445 -
1446                                         if (!isdigit((unsigned char)pattern[k + 1])) {
1447                                                 /* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */
1448                                                 buffer_append_string_len(p->location, pattern+k, pattern[k] == pattern[k+1] ? 1 : 2);
1449 Index: src/mod_webdav.c
1450 ===================================================================
1451 --- src/mod_webdav.c    (.../tags/lighttpd-1.4.23)
1452 +++ src/mod_webdav.c    (.../branches/lighttpd-1.4.x)
1453 @@ -1096,6 +1096,7 @@
1454  }
1455  #endif
1456  
1457 +#ifdef USE_LOCKS
1458  static int webdav_lockdiscovery(server *srv, connection *con,
1459                 buffer *locktoken, const char *lockscope, const char *locktype, int depth) {
1460  
1461 @@ -1150,6 +1151,8 @@
1462  
1463         return 0;
1464  }
1465 +#endif
1466 +
1467  /**
1468   * check if resource is having the right locks to access to resource
1469   *
1470 Index: src/configparser.y
1471 ===================================================================
1472 --- src/configparser.y  (.../tags/lighttpd-1.4.23)
1473 +++ src/configparser.y  (.../branches/lighttpd-1.4.x)
1474 @@ -72,7 +72,7 @@
1475        op1->free(op1);
1476        return (data_unset *)ds;
1477      } else {
1478 -      fprintf(stderr, "data type mismatch, cannot be merge\n");
1479 +      fprintf(stderr, "data type mismatch, cannot merge\n");
1480        return NULL;
1481      }
1482    }
1483 @@ -193,7 +193,6 @@
1484      du = configparser_merge_data(du, B);
1485      if (NULL == du) {
1486        ctx->ok = 0;
1487 -      du->free(du);
1488      }
1489      else {
1490        buffer_copy_string_buffer(du->key, A);
1491 @@ -470,7 +469,7 @@
1492      case CONFIG_COND_MATCH: {
1493  #ifdef HAVE_PCRE_H
1494        const char *errptr;
1495 -      int erroff;
1496 +      int erroff, captures;
1497  
1498        if (NULL == (dc->regex =
1499            pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) {
1500 @@ -487,6 +486,14 @@
1501          fprintf(stderr, "studying regex failed: %s -> %s\n",
1502              rvalue->ptr, errptr);
1503          ctx->ok = 0;
1504 +      } else if (0 != (pcre_fullinfo(dc->regex, dc->regex_study, PCRE_INFO_CAPTURECOUNT, &captures))) {
1505 +        fprintf(stderr, "getting capture count for regex failed: %s\n",
1506 +            rvalue->ptr);
1507 +        ctx->ok = 0;
1508 +      } else if (captures > 9) {
1509 +        fprintf(stderr, "Too many captures in regex, use (?:...) instead of (...): %s\n",
1510 +            rvalue->ptr);
1511 +        ctx->ok = 0;
1512        } else {
1513          dc->string = buffer_init_buffer(rvalue);
1514        }
1515 Index: src/mod_status.c
1516 ===================================================================
1517 --- src/mod_status.c    (.../tags/lighttpd-1.4.23)
1518 +++ src/mod_status.c    (.../branches/lighttpd-1.4.x)
1519 @@ -438,7 +438,7 @@
1520  
1521         buffer_append_string_len(b, CONST_STR_LEN(
1522                 "<hr />\n<pre><b>legend</b>\n"
1523 -               ". = connect, C = close, E = hard error\n"
1524 +               ". = connect, C = close, E = hard error, k = keep-alive\n"
1525                 "r = read, R = read-POST, W = write, h = handle-request\n"
1526                 "q = request-start,  Q = request-end\n"
1527                 "s = response-start, S = response-end\n"));
1528 @@ -449,8 +449,14 @@
1529  
1530         for (j = 0; j < srv->conns->used; j++) {
1531                 connection *c = srv->conns->ptr[j];
1532 -               const char *state = connection_get_short_state(c->state);
1533 +               const char *state;
1534  
1535 +               if (CON_STATE_READ == c->state && c->request.orig_uri->used > 0) {
1536 +                       state = "k";
1537 +               } else {
1538 +                       state = connection_get_short_state(c->state);
1539 +               }
1540 +
1541                 buffer_append_string_len(b, state, 1);
1542  
1543                 if (((j + 1) % 50) == 0) {
1544 @@ -497,7 +503,11 @@
1545  
1546                 buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
1547  
1548 -               buffer_append_string(b, connection_get_state(c->state));
1549 +               if (CON_STATE_READ == c->state && c->request.orig_uri->used > 0) {
1550 +                       buffer_append_string_len(b, CONST_STR_LEN("keep-alive"));
1551 +               } else {
1552 +                       buffer_append_string(b, connection_get_state(c->state));
1553 +               }
1554  
1555                 buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
1556  
1557 @@ -611,10 +621,10 @@
1558  }
1559  
1560  static handler_t mod_status_handle_server_statistics(server *srv, connection *con, void *p_d) {
1561 -       plugin_data *p = p_d;
1562 -       buffer *b = p->module_list;
1563 +       buffer *b;
1564         size_t i;
1565         array *st = srv->status;
1566 +       UNUSED(p_d);
1567  
1568         if (0 == st->used) {
1569                 /* we have nothing to send */
1570 Index: src/mod_ssi.c
1571 ===================================================================
1572 --- src/mod_ssi.c       (.../tags/lighttpd-1.4.23)
1573 +++ src/mod_ssi.c       (.../branches/lighttpd-1.4.x)
1574 @@ -362,7 +362,8 @@
1575         switch(ssicmd) {
1576         case SSI_ECHO: {
1577                 /* echo */
1578 -               int var = 0, enc = 0;
1579 +               int var = 0;
1580 +               /* int enc = 0; */
1581                 const char *var_val = NULL;
1582                 stat_cache_entry *sce = NULL;
1583  
1584 @@ -381,6 +382,7 @@
1585                         { NULL, SSI_ECHO_UNSET }
1586                 };
1587  
1588 +/*
1589                 struct {
1590                         const char *var;
1591                         enum { SSI_ENC_UNSET, SSI_ENC_URL, SSI_ENC_NONE, SSI_ENC_ENTITY } type;
1592 @@ -391,6 +393,7 @@
1593  
1594                         { NULL, SSI_ENC_UNSET }
1595                 };
1596 +*/
1597  
1598                 for (i = 2; i < n; i += 2) {
1599                         if (0 == strcmp(l[i], "var")) {
1600 @@ -405,6 +408,7 @@
1601                                         }
1602                                 }
1603                         } else if (0 == strcmp(l[i], "encoding")) {
1604 +/*
1605                                 int j;
1606  
1607                                 for (j = 0; encvars[j].var; j++) {
1608 @@ -413,6 +417,7 @@
1609                                                 break;
1610                                         }
1611                                 }
1612 +*/
1613                         } else {
1614                                 log_error_write(srv, __FILE__, __LINE__, "sss",
1615                                                 "ssi: unknow attribute for ",
1616 Index: src/mod_auth.c
1617 ===================================================================
1618 --- src/mod_auth.c      (.../tags/lighttpd-1.4.23)
1619 +++ src/mod_auth.c      (.../branches/lighttpd-1.4.x)
1620 @@ -468,7 +468,7 @@
1621  
1622                         if (method == NULL) {
1623                                 log_error_write(srv, __FILE__, __LINE__, "ss",
1624 -                                               "the require field is missing in:",
1625 +                                               "the method field is missing in:",
1626                                                 "auth.require = ( \"...\" => ( ..., \"method\" => \"...\" ) )");
1627                                 return HANDLER_ERROR;
1628                         } else {
1629 @@ -483,7 +483,7 @@
1630  
1631                         if (realm == NULL) {
1632                                 log_error_write(srv, __FILE__, __LINE__, "ss",
1633 -                                               "the require field is missing in:",
1634 +                                               "the realm field is missing in:",
1635                                                 "auth.require = ( \"...\" => ( ..., \"realm\" => \"...\" ) )");
1636                                 return HANDLER_ERROR;
1637                         }
1638 Index: src/mod_cml_lua.c
1639 ===================================================================
1640 --- src/mod_cml_lua.c   (.../tags/lighttpd-1.4.23)
1641 +++ src/mod_cml_lua.c   (.../branches/lighttpd-1.4.x)
1642 @@ -2,6 +2,7 @@
1643  #include <stdio.h>
1644  #include <errno.h>
1645  #include <time.h>
1646 +#include <string.h>
1647  
1648  #include "mod_cml.h"
1649  #include "mod_cml_funcs.h"
1650 Index: src/http-header-glue.c
1651 ===================================================================
1652 --- src/http-header-glue.c      (.../tags/lighttpd-1.4.23)
1653 +++ src/http-header-glue.c      (.../branches/lighttpd-1.4.x)
1654 @@ -104,6 +104,21 @@
1655         return response_header_insert(srv, con, key, keylen, value, vallen);
1656  }
1657  
1658 +int response_header_append(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen) {
1659 +       data_string *ds;
1660 +
1661 +       UNUSED(srv);
1662 +
1663 +       /* if there already is a key by this name append the value */
1664 +       if (NULL != (ds = (data_string *)array_get_element(con->response.headers, key))) {
1665 +               buffer_append_string_len(ds->value, CONST_STR_LEN(", "));
1666 +               buffer_append_string_len(ds->value, value, vallen);
1667 +               return 0;
1668 +       }
1669 +
1670 +       return response_header_insert(srv, con, key, keylen, value, vallen);
1671 +}
1672 +
1673  int http_response_redirect_to_directory(server *srv, connection *con) {
1674         buffer *o;
1675  
1676 @@ -259,7 +274,7 @@
1677                                         }
1678  
1679                                         if (0 == strncmp(con->request.http_if_modified_since, mtime->ptr, used_len)) {
1680 -                                               con->http_status = 304;
1681 +                                               if ('\0' == mtime->ptr[used_len]) con->http_status = 304;
1682                                                 return HANDLER_FINISHED;
1683                                         } else {
1684                                                 char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
1685 @@ -281,15 +296,16 @@
1686                                                 strncpy(buf, con->request.http_if_modified_since, used_len);
1687                                                 buf[used_len] = '\0';
1688  
1689 -                                               tm.tm_isdst = 0;
1690                                                 if (NULL == strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm)) {
1691                                                         con->http_status = 412;
1692                                                         con->mode = DIRECT;
1693                                                         return HANDLER_FINISHED;
1694                                                 }
1695 +                                               tm.tm_isdst = 0;
1696                                                 t_header = mktime(&tm);
1697  
1698                                                 strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
1699 +                                               tm.tm_isdst = 0;
1700                                                 t_file = mktime(&tm);
1701  
1702                                                 if (t_file > t_header) return HANDLER_GO_ON;
1703 @@ -318,7 +334,7 @@
1704                 }
1705  
1706                 if (0 == strncmp(con->request.http_if_modified_since, mtime->ptr, used_len)) {
1707 -                       con->http_status = 304;
1708 +                       if ('\0' == mtime->ptr[used_len]) con->http_status = 304;
1709                         return HANDLER_FINISHED;
1710                 } else {
1711                         char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
1712 @@ -331,18 +347,17 @@
1713                         strncpy(buf, con->request.http_if_modified_since, used_len);
1714                         buf[used_len] = '\0';
1715  
1716 -                       tm.tm_isdst = 0;
1717                         if (NULL == strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm)) {
1718                                 /**
1719                                  * parsing failed, let's get out of here 
1720                                  */
1721 -                               log_error_write(srv, __FILE__, __LINE__, "ss",
1722 -                                               "strptime() failed on", buf);
1723                                 return HANDLER_GO_ON;
1724                         }
1725 +                       tm.tm_isdst = 0;
1726                         t_header = mktime(&tm);
1727  
1728                         strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
1729 +                       tm.tm_isdst = 0;
1730                         t_file = mktime(&tm);
1731  
1732                         if (t_file > t_header) return HANDLER_GO_ON;
1733 Index: src/mod_setenv.c
1734 ===================================================================
1735 --- src/mod_setenv.c    (.../tags/lighttpd-1.4.23)
1736 +++ src/mod_setenv.c    (.../branches/lighttpd-1.4.x)
1737 @@ -215,7 +215,7 @@
1738         return HANDLER_GO_ON;
1739  }
1740  
1741 -REQUESTDONE_FUNC(mod_setenv_reset) {
1742 +CONNECTION_FUNC(mod_setenv_reset) {
1743         plugin_data *p = p_d;
1744  
1745         UNUSED(srv);
1746 @@ -240,7 +240,7 @@
1747         p->set_defaults  = mod_setenv_set_defaults;
1748         p->cleanup     = mod_setenv_free;
1749  
1750 -       p->handle_request_done  = mod_setenv_reset;
1751 +       p->connection_reset  = mod_setenv_reset;
1752  
1753         p->data        = NULL;
1754  
1755 Index: src/mod_fastcgi.c
1756 ===================================================================
1757 --- src/mod_fastcgi.c   (.../tags/lighttpd-1.4.23)
1758 +++ src/mod_fastcgi.c   (.../branches/lighttpd-1.4.x)
1759 @@ -122,24 +122,11 @@
1760          *
1761          */
1762  
1763 -       unsigned short min_procs;
1764         unsigned short max_procs;
1765         size_t num_procs;    /* how many procs are started */
1766         size_t active_procs; /* how many of them are really running */
1767  
1768 -       unsigned short max_load_per_proc;
1769 -
1770         /*
1771 -        * kick the process from the list if it was not
1772 -        * used for idle_timeout until min_procs is
1773 -        * reached. this helps to get the processlist
1774 -        * small again we had a small peak load.
1775 -        *
1776 -        */
1777 -
1778 -       unsigned short idle_timeout;
1779 -
1780 -       /*
1781          * time after a disabled remote connection is tried to be re-enabled
1782          *
1783          *
1784 @@ -384,6 +371,21 @@
1785  /* ok, we need a prototype */
1786  static handler_t fcgi_handle_fdevent(void *s, void *ctx, int revents);
1787  
1788 +static void reset_signals(void) {
1789 +#ifdef SIGTTOU
1790 +       signal(SIGTTOU, SIG_DFL);
1791 +#endif
1792 +#ifdef SIGTTIN
1793 +       signal(SIGTTIN, SIG_DFL);
1794 +#endif
1795 +#ifdef SIGTSTP
1796 +       signal(SIGTSTP, SIG_DFL);
1797 +#endif
1798 +       signal(SIGHUP, SIG_DFL);
1799 +       signal(SIGPIPE, SIG_DFL);
1800 +       signal(SIGUSR1, SIG_DFL);
1801 +}
1802 +
1803  static void fastcgi_status_copy_procname(buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
1804         buffer_copy_string_len(b, CONST_STR_LEN("fastcgi.backend."));
1805         buffer_append_string_buffer(b, host->id);
1806 @@ -993,8 +995,6 @@
1807                                 close(fcgi_fd);
1808                         }
1809  
1810 -                       openDevNull(STDERR_FILENO);
1811 -
1812                         /* we don't need the client socket */
1813                         for (i = 3; i < 256; i++) {
1814                                 close(i);
1815 @@ -1054,6 +1054,7 @@
1816                                 *c = '/';
1817                         }
1818  
1819 +                       reset_signals();
1820  
1821                         /* exec the cgi */
1822                         execve(arg.ptr[0], arg.ptr, env.ptr);
1823 @@ -1235,20 +1236,17 @@
1824  
1825                                                 { "check-local",       NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },      /* 5 */
1826                                                 { "port",              NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 6 */
1827 -                                               { "min-procs-not-working",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 7 this is broken for now */
1828 -                                               { "max-procs",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 8 */
1829 -                                               { "max-load-per-proc", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 9 */
1830 -                                               { "idle-timeout",      NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 10 */
1831 -                                               { "disable-time",      NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 11 */
1832 +                                               { "max-procs",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 7 */
1833 +                                               { "disable-time",      NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 8 */
1834  
1835 -                                               { "bin-environment",   NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },        /* 12 */
1836 -                                               { "bin-copy-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },     /* 13 */
1837 +                                               { "bin-environment",   NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },        /* 9 */
1838 +                                               { "bin-copy-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },     /* 10 */
1839  
1840 -                                               { "broken-scriptfilename", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },  /* 14 */
1841 -                                               { "allow-x-send-file",  NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },      /* 15 */
1842 -                                               { "strip-request-uri",  NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 16 */
1843 -                                               { "kill-signal",        NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },      /* 17 */
1844 -                                               { "fix-root-scriptname",   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },  /* 18 */
1845 +                                               { "broken-scriptfilename", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },  /* 11 */
1846 +                                               { "allow-x-send-file",  NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },     /* 12 */
1847 +                                               { "strip-request-uri",  NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 13 */
1848 +                                               { "kill-signal",        NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 14 */
1849 +                                               { "fix-root-scriptname",   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },  /* 15 */
1850  
1851                                                 { NULL,                NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
1852                                         };
1853 @@ -1267,12 +1265,9 @@
1854                                         buffer_copy_string_buffer(host->id, da_host->key);
1855  
1856                                         host->check_local  = 1;
1857 -                                       host->min_procs    = 4;
1858                                         host->max_procs    = 4;
1859 -                                       host->max_load_per_proc = 1;
1860 -                                       host->idle_timeout = 60;
1861                                         host->mode = FCGI_RESPONDER;
1862 -                                       host->disable_time = 60;
1863 +                                       host->disable_time = 1;
1864                                         host->break_scriptfilename_for_php = 0;
1865                                         host->allow_xsendfile = 0; /* handle X-LIGHTTPD-send-file */
1866                                         host->kill_signal = SIGTERM;
1867 @@ -1286,19 +1281,16 @@
1868  
1869                                         fcv[5].destination = &(host->check_local);
1870                                         fcv[6].destination = &(host->port);
1871 -                                       fcv[7].destination = &(host->min_procs);
1872 -                                       fcv[8].destination = &(host->max_procs);
1873 -                                       fcv[9].destination = &(host->max_load_per_proc);
1874 -                                       fcv[10].destination = &(host->idle_timeout);
1875 -                                       fcv[11].destination = &(host->disable_time);
1876 +                                       fcv[7].destination = &(host->max_procs);
1877 +                                       fcv[8].destination = &(host->disable_time);
1878  
1879 -                                       fcv[12].destination = host->bin_env;
1880 -                                       fcv[13].destination = host->bin_env_copy;
1881 -                                       fcv[14].destination = &(host->break_scriptfilename_for_php);
1882 -                                       fcv[15].destination = &(host->allow_xsendfile);
1883 -                                       fcv[16].destination = host->strip_request_uri;
1884 -                                       fcv[17].destination = &(host->kill_signal);
1885 -                                       fcv[18].destination = &(host->fix_root_path_name);
1886 +                                       fcv[9].destination = host->bin_env;
1887 +                                       fcv[10].destination = host->bin_env_copy;
1888 +                                       fcv[11].destination = &(host->break_scriptfilename_for_php);
1889 +                                       fcv[12].destination = &(host->allow_xsendfile);
1890 +                                       fcv[13].destination = host->strip_request_uri;
1891 +                                       fcv[14].destination = &(host->kill_signal);
1892 +                                       fcv[15].destination = &(host->fix_root_path_name);
1893  
1894                                         if (0 != config_insert_values_internal(srv, da_host->value, fcv)) {
1895                                                 return HANDLER_ERROR;
1896 @@ -1355,23 +1347,16 @@
1897                                                 /* a local socket + self spawning */
1898                                                 size_t pno;
1899  
1900 -                                               /* HACK:  just to make sure the adaptive spawing is disabled */
1901 -                                               host->min_procs = host->max_procs;
1902 -
1903 -                                               if (host->min_procs > host->max_procs) host->max_procs = host->min_procs;
1904 -                                               if (host->max_load_per_proc < 1) host->max_load_per_proc = 0;
1905 -
1906                                                 if (s->debug) {
1907 -                                                       log_error_write(srv, __FILE__, __LINE__, "ssbsdsbsdsd",
1908 +                                                       log_error_write(srv, __FILE__, __LINE__, "ssbsdsbsd",
1909                                                                         "--- fastcgi spawning local",
1910                                                                         "\n\tproc:", host->bin_path,
1911                                                                         "\n\tport:", host->port,
1912                                                                         "\n\tsocket", host->unixsocket,
1913 -                                                                       "\n\tmin-procs:", host->min_procs,
1914                                                                         "\n\tmax-procs:", host->max_procs);
1915                                                 }
1916  
1917 -                                               for (pno = 0; pno < host->min_procs; pno++) {
1918 +                                               for (pno = 0; pno < host->max_procs; pno++) {
1919                                                         fcgi_proc *proc;
1920  
1921                                                         proc = fastcgi_process_init();
1922 @@ -1391,7 +1376,7 @@
1923                                                                                 "--- fastcgi spawning",
1924                                                                                 "\n\tport:", host->port,
1925                                                                                 "\n\tsocket", host->unixsocket,
1926 -                                                                               "\n\tcurrent:", pno, "/", host->min_procs);
1927 +                                                                               "\n\tcurrent:", pno, "/", host->max_procs);
1928                                                         }
1929  
1930                                                         if (fcgi_spawn_connection(srv, p, host, proc)) {
1931 @@ -1426,7 +1411,6 @@
1932  
1933                                                 host->first = proc;
1934  
1935 -                                               host->min_procs = 1;
1936                                                 host->max_procs = 1;
1937                                         }
1938  
1939 @@ -2739,7 +2723,7 @@
1940                                         log_error_write(srv, __FILE__, __LINE__, "ssbsdsd",
1941                                                         "--- fastcgi spawning",
1942                                                         "\n\tsocket", proc->connection_name,
1943 -                                                       "\n\tcurrent:", 1, "/", host->min_procs);
1944 +                                                       "\n\tcurrent:", 1, "/", host->max_procs);
1945                                 }
1946  
1947                                 if (fcgi_spawn_connection(srv, p, host, proc)) {
1948 @@ -2778,8 +2762,11 @@
1949          *     - tcp socket (do not check host->host->uses, as it may be not set which means INADDR_LOOPBACK)
1950          *     - unix socket
1951          */
1952 -       if (!host ||
1953 -           (!host->port && !host->unixsocket->used)) {
1954 +       if (!host) {
1955 +               log_error_write(srv, __FILE__, __LINE__, "s", "fatal error: host = NULL");
1956 +               return HANDLER_ERROR;
1957 +       }
1958 +       if ((!host->port && !host->unixsocket->used)) {
1959                 log_error_write(srv, __FILE__, __LINE__, "sxddd",
1960                                 "write-req: error",
1961                                 host,
1962 @@ -2787,7 +2774,7 @@
1963                                 host->port,
1964                                 host->unixsocket->used);
1965  
1966 -               hctx->proc->disabled_until = srv->cur_ts + 10;
1967 +               hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
1968                 hctx->proc->state = PROC_STATE_DIED;
1969  
1970                 return HANDLER_ERROR;
1971 @@ -2803,7 +2790,7 @@
1972                         log_error_write(srv, __FILE__, __LINE__, "ss",
1973                                         "getsockopt failed:", strerror(errno));
1974  
1975 -                       hctx->proc->disabled_until = srv->cur_ts + 10;
1976 +                       hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
1977                         hctx->proc->state = PROC_STATE_DIED;
1978  
1979                         return HANDLER_ERROR;
1980 @@ -2817,7 +2804,7 @@
1981                                                 "socket:", hctx->proc->connection_name);
1982                         }
1983  
1984 -                       hctx->proc->disabled_until = srv->cur_ts + 5;
1985 +                       hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
1986  
1987                         if (hctx->proc->is_local) {
1988                                 hctx->proc->state = PROC_STATE_DIED_WAIT_FOR_PID;
1989 @@ -2910,13 +2897,13 @@
1990                         /* cool down the backend, it is overloaded
1991                          * -> EAGAIN */
1992  
1993 -                       log_error_write(srv, __FILE__, __LINE__, "ssdsd",
1994 -                               "backend is overloaded; we'll disable it for 2 seconds and send the request to another backend instead:",
1995 +                       log_error_write(srv, __FILE__, __LINE__, "sdssdsd",
1996 +                               "backend is overloaded; we'll disable it for", hctx->host->disable_time, "seconds and send the request to another backend instead:",
1997                                 "reconnects:", hctx->reconnects,
1998                                 "load:", host->load);
1999  
2000  
2001 -                       hctx->proc->disabled_until = srv->cur_ts + 2;
2002 +                       hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
2003                         hctx->proc->state = PROC_STATE_OVERLOADED;
2004  
2005                         fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
2006 @@ -2930,18 +2917,18 @@
2007                          * - ECONNREFUSED for tcp-ip sockets
2008                          * - ENOENT for unix-domain-sockets
2009                          *
2010 -                        * for check if the host is back in 5 seconds
2011 +                        * for check if the host is back in hctx->host->disable_time seconds
2012                          *  */
2013  
2014 -                       hctx->proc->disabled_until = srv->cur_ts + 5;
2015 +                       hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
2016                         if (hctx->proc->is_local) {
2017                                 hctx->proc->state = PROC_STATE_DIED_WAIT_FOR_PID;
2018                         } else {
2019                                 hctx->proc->state = PROC_STATE_DIED;
2020                         }
2021  
2022 -                       log_error_write(srv, __FILE__, __LINE__, "ssdsd",
2023 -                               "backend died; we'll disable it for 5 seconds and send the request to another backend instead:",
2024 +                       log_error_write(srv, __FILE__, __LINE__, "sdssdsd",
2025 +                               "backend died; we'll disable it for", hctx->host->disable_time, "seconds and send the request to another backend instead:",
2026                                 "reconnects:", hctx->reconnects,
2027                                 "load:", host->load);
2028  
2029 @@ -3032,11 +3019,6 @@
2030                                                 "reconnect attempts:", hctx->reconnects);
2031  
2032                                 return HANDLER_ERROR;
2033 -                       case EAGAIN:
2034 -                       case EINTR:
2035 -                               fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
2036 -
2037 -                               return HANDLER_WAIT_FOR_EVENT;
2038                         default:
2039                                 log_error_write(srv, __FILE__, __LINE__, "ssd",
2040                                                 "write failed:", strerror(errno), errno);
2041 @@ -3266,7 +3248,7 @@
2042                                                 log_error_write(srv, __FILE__, __LINE__, "ssbsdsd",
2043                                                                 "--- fastcgi spawning",
2044                                                                 "\n\tsocket", proc->connection_name,
2045 -                                                               "\n\tcurrent:", 1, "/", host->min_procs);
2046 +                                                               "\n\tcurrent:", 1, "/", host->max_procs);
2047                                         }
2048  
2049                                         if (fcgi_spawn_connection(srv, p, host, proc)) {
2050 @@ -3288,18 +3270,18 @@
2051                                     hctx->reconnects < 5) {
2052                                         fcgi_reconnect(srv, hctx);
2053  
2054 -                                       log_error_write(srv, __FILE__, __LINE__, "ssbsbs",
2055 +                                       log_error_write(srv, __FILE__, __LINE__, "ssbsBSBs",
2056                                                 "response not received, request not sent",
2057                                                 "on socket:", proc->connection_name,
2058 -                                               "for", con->uri.path, ", reconnecting");
2059 +                                               "for", con->uri.path, "?", con->uri.query, ", reconnecting");
2060  
2061                                         return HANDLER_WAIT_FOR_FD;
2062                                 }
2063  
2064 -                               log_error_write(srv, __FILE__, __LINE__, "sosbsbs",
2065 +                               log_error_write(srv, __FILE__, __LINE__, "sosbsBSBs",
2066                                                 "response not received, request sent:", hctx->wb->bytes_out,
2067                                                 "on socket:", proc->connection_name,
2068 -                                               "for", con->uri.path, ", closing connection");
2069 +                                               "for", con->uri.path, "?", con->uri.query, ", closing connection");
2070  
2071                                 fcgi_connection_close(srv, hctx);
2072  
2073 @@ -3311,10 +3293,10 @@
2074                                 /* response might have been already started, kill the connection */
2075                                 fcgi_connection_close(srv, hctx);
2076  
2077 -                               log_error_write(srv, __FILE__, __LINE__, "ssbsbs",
2078 +                               log_error_write(srv, __FILE__, __LINE__, "ssbsBSBs",
2079                                                 "response already sent out, but backend returned error",
2080                                                 "on socket:", proc->connection_name,
2081 -                                               "for", con->uri.path, ", terminating connection");
2082 +                                               "for", con->uri.path, "?", con->uri.query, ", terminating connection");
2083  
2084                                 connection_set_state(srv, con, CON_STATE_ERROR);
2085                         }
2086 @@ -3364,9 +3346,9 @@
2087                          * even if the FCGI_FIN packet is not received yet
2088                          */
2089                 } else {
2090 -                       log_error_write(srv, __FILE__, __LINE__, "sbsbsd",
2091 +                       log_error_write(srv, __FILE__, __LINE__, "sBSbsbsd",
2092                                         "error: unexpected close of fastcgi connection for",
2093 -                                       con->uri.path,
2094 +                                       con->uri.path, "?", con->uri.query,
2095                                         "(no fastcgi process on socket:", proc->connection_name, "?)",
2096                                         hctx->state);
2097  
2098 @@ -3489,25 +3471,27 @@
2099                 /* check if extension matches */
2100                 for (k = 0; k < p->conf.exts->used; k++) {
2101                         size_t ct_len; /* length of the config entry */
2102 +                       fcgi_extension *ext = p->conf.exts->exts[k];
2103  
2104 -                       extension = p->conf.exts->exts[k];
2105 +                       if (ext->key->used == 0) continue;
2106  
2107 -                       if (extension->key->used == 0) continue;
2108 +                       ct_len = ext->key->used - 1;
2109  
2110 -                       ct_len = extension->key->used - 1;
2111 -
2112                         /* check _url_ in the form "/fcgi_pattern" */
2113 -                       if (extension->key->ptr[0] == '/') {
2114 +                       if (ext->key->ptr[0] == '/') {
2115                                 if ((ct_len <= con->uri.path->used -1) &&
2116 -                                   (strncmp(con->uri.path->ptr, extension->key->ptr, ct_len) == 0))
2117 +                                   (strncmp(con->uri.path->ptr, ext->key->ptr, ct_len) == 0)) {
2118 +                                       extension = ext;
2119                                         break;
2120 -                       } else if ((ct_len <= s_len) && (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len))) {
2121 +                               }
2122 +                       } else if ((ct_len <= s_len) && (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len))) {
2123                                 /* check extension in the form ".fcg" */
2124 +                               extension = ext;
2125                                 break;
2126                         }
2127                 }
2128                 /* extension doesn't match */
2129 -               if (k == p->conf.exts->used) {
2130 +               if (NULL == extension) {
2131                         return HANDLER_GO_ON;
2132                 }
2133         }
2134 @@ -3535,8 +3519,8 @@
2135                 if (!extension->note_is_sent) {
2136                         extension->note_is_sent = 1;
2137  
2138 -                       log_error_write(srv, __FILE__, __LINE__, "sbsbs",
2139 -                                       "all handlers for ", con->uri.path,
2140 +                       log_error_write(srv, __FILE__, __LINE__, "sBSbsbs",
2141 +                                       "all handlers for", con->uri.path, "?", con->uri.query,
2142                                         "on", extension->key,
2143                                         "are down.");
2144                 }
2145 @@ -3727,107 +3711,12 @@
2146                         for (n = 0; n < ex->used; n++) {
2147  
2148                                 fcgi_proc *proc;
2149 -                               unsigned long sum_load = 0;
2150                                 fcgi_extension_host *host;
2151  
2152                                 host = ex->hosts[n];
2153  
2154                                 fcgi_restart_dead_procs(srv, p, host);
2155  
2156 -                               for (proc = host->first; proc; proc = proc->next) {
2157 -                                       sum_load += proc->load;
2158 -                               }
2159 -
2160 -                               if (host->num_procs &&
2161 -                                   host->num_procs < host->max_procs &&
2162 -                                   (sum_load / host->num_procs) > host->max_load_per_proc) {
2163 -                                       /* overload, spawn new child */
2164 -                                       if (p->conf.debug) {
2165 -                                               log_error_write(srv, __FILE__, __LINE__, "s",
2166 -                                                               "overload detected, spawning a new child");
2167 -                                       }
2168 -
2169 -                                       for (proc = host->unused_procs; proc && proc->pid != 0; proc = proc->next);
2170 -
2171 -                                       if (proc) {
2172 -                                               if (proc == host->unused_procs) host->unused_procs = proc->next;
2173 -
2174 -                                               if (proc->next) proc->next->prev = NULL;
2175 -
2176 -                                               host->max_id++;
2177 -                                       } else {
2178 -                                               proc = fastcgi_process_init();
2179 -                                               proc->id = host->max_id++;
2180 -                                       }
2181 -
2182 -                                       host->num_procs++;
2183 -
2184 -                                       if (buffer_is_empty(host->unixsocket)) {
2185 -                                               proc->port = host->port + proc->id;
2186 -                                       } else {
2187 -                                               buffer_copy_string_buffer(proc->unixsocket, host->unixsocket);
2188 -                                               buffer_append_string_len(proc->unixsocket, CONST_STR_LEN("-"));
2189 -                                               buffer_append_long(proc->unixsocket, proc->id);
2190 -                                       }
2191 -
2192 -                                       if (fcgi_spawn_connection(srv, p, host, proc)) {
2193 -                                               log_error_write(srv, __FILE__, __LINE__, "s",
2194 -                                                               "ERROR: spawning fcgi failed.");
2195 -                                               return HANDLER_ERROR;
2196 -                                       }
2197 -
2198 -                                       proc->prev = NULL;
2199 -                                       proc->next = host->first;
2200 -                                       if (host->first) {
2201 -                                               host->first->prev = proc;
2202 -                                       }
2203 -                                       host->first = proc;
2204 -                               }
2205 -
2206 -                               for (proc = host->first; proc; proc = proc->next) {
2207 -                                       if (proc->load != 0) break;
2208 -                                       if (host->num_procs <= host->min_procs) break;
2209 -                                       if (proc->pid == 0) continue;
2210 -
2211 -                                       if (srv->cur_ts - proc->last_used > host->idle_timeout) {
2212 -                                               /* a proc is idling for a long time now,
2213 -                                                * terminate it */
2214 -
2215 -                                               if (p->conf.debug) {
2216 -                                                       log_error_write(srv, __FILE__, __LINE__, "ssbsd",
2217 -                                                                       "idle-timeout reached; terminating child:",
2218 -                                                                       "socket:", proc->connection_name,
2219 -                                                                       "pid", proc->pid);
2220 -                                               }
2221 -
2222 -
2223 -                                               if (proc->next) proc->next->prev = proc->prev;
2224 -                                               if (proc->prev) proc->prev->next = proc->next;
2225 -
2226 -                                               if (proc->prev == NULL) host->first = proc->next;
2227 -
2228 -                                               proc->prev = NULL;
2229 -                                               proc->next = host->unused_procs;
2230 -
2231 -                                               if (host->unused_procs) host->unused_procs->prev = proc;
2232 -                                               host->unused_procs = proc;
2233 -
2234 -                                               kill(proc->pid, SIGTERM);
2235 -
2236 -                                               proc->state = PROC_STATE_KILLED;
2237 -
2238 -                                               log_error_write(srv, __FILE__, __LINE__, "ssbsd",
2239 -                                                                       "killed:",
2240 -                                                                       "socket:", proc->connection_name,
2241 -                                                                       "pid", proc->pid);
2242 -
2243 -                                               host->num_procs--;
2244 -
2245 -                                               /* proc is now in unused, let the next second handle the next process */
2246 -                                               break;
2247 -                                       }
2248 -                               }
2249 -
2250                                 for (proc = host->unused_procs; proc; proc = proc->next) {
2251                                         int status;
2252  
2253 Index: src/fdevent_poll.c
2254 ===================================================================
2255 --- src/fdevent_poll.c  (.../tags/lighttpd-1.4.23)
2256 +++ src/fdevent_poll.c  (.../branches/lighttpd-1.4.x)
2257 @@ -132,7 +132,7 @@
2258         if (poll_r & POLLNVAL) r |= FDEVENT_NVAL;
2259         if (poll_r & POLLPRI) r |= FDEVENT_PRI;
2260  
2261 -       return ev->pollfds[ndx].revents;
2262 +       return r;
2263  }
2264  
2265  static int fdevent_poll_event_get_fd(fdevents *ev, size_t ndx) {
2266 Index: src/fdevent_select.c
2267 ===================================================================
2268 --- src/fdevent_select.c        (.../tags/lighttpd-1.4.23)
2269 +++ src/fdevent_select.c        (.../branches/lighttpd-1.4.x)
2270 @@ -38,7 +38,7 @@
2271         UNUSED(fde_ndx);
2272  
2273         /* we should be protected by max-fds, but you never know */
2274 -       assert(fd < FD_SETSIZE);
2275 +       assert(fd < ((int)FD_SETSIZE));
2276  
2277         if (events & FDEVENT_IN) {
2278                 FD_SET(fd, &(ev->select_set_read));
2279 Index: src/CMakeLists.txt
2280 ===================================================================
2281 Index: src/server.c
2282 ===================================================================
2283 --- src/server.c        (.../tags/lighttpd-1.4.23)
2284 +++ src/server.c        (.../branches/lighttpd-1.4.x)
2285 @@ -187,6 +187,7 @@
2286         CLEAN(cond_check_buf);
2287  
2288         CLEAN(srvconf.errorlog_file);
2289 +       CLEAN(srvconf.breakagelog_file);
2290         CLEAN(srvconf.groupname);
2291         CLEAN(srvconf.username);
2292         CLEAN(srvconf.changeroot);
2293 @@ -242,8 +243,8 @@
2294         srv->srvconf.reject_expect_100_with_417 = 1;
2295  
2296         /* use syslog */
2297 -       srv->errorlog_fd = -1;
2298 -       srv->errorlog_mode = ERRORLOG_STDERR;
2299 +       srv->errorlog_fd = STDERR_FILENO;
2300 +       srv->errorlog_mode = ERRORLOG_FD;
2301  
2302         srv->split_vals = array_init();
2303  
2304 @@ -271,6 +272,7 @@
2305         CLEAN(cond_check_buf);
2306  
2307         CLEAN(srvconf.errorlog_file);
2308 +       CLEAN(srvconf.breakagelog_file);
2309         CLEAN(srvconf.groupname);
2310         CLEAN(srvconf.username);
2311         CLEAN(srvconf.changeroot);
2312 @@ -717,7 +719,7 @@
2313                 }
2314  
2315                 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
2316 -                       srv->max_fds = rlim.rlim_cur < FD_SETSIZE - 200 ? rlim.rlim_cur : FD_SETSIZE - 200;
2317 +                       srv->max_fds = rlim.rlim_cur < ((int)FD_SETSIZE) - 200 ? rlim.rlim_cur : FD_SETSIZE - 200;
2318                 } else {
2319                         srv->max_fds = rlim.rlim_cur;
2320                 }
2321 @@ -730,7 +732,7 @@
2322  #endif
2323                 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
2324                         /* don't raise the limit above FD_SET_SIZE */
2325 -                       if (srv->max_fds > FD_SETSIZE - 200) {
2326 +                       if (srv->max_fds > ((int)FD_SETSIZE) - 200) {
2327                                 log_error_write(srv, __FILE__, __LINE__, "sd",
2328                                                 "can't raise max filedescriptors above",  FD_SETSIZE - 200,
2329                                                 "if event-handler is 'select'. Use 'poll' or something else or reduce server.max-fds.");
2330 @@ -780,7 +782,7 @@
2331                  * Change group before chroot, when we have access
2332                  * to /etc/group
2333                  * */
2334 -               if (srv->srvconf.groupname->used) {
2335 +               if (NULL != grp) {
2336                         setgid(grp->gr_gid);
2337                         setgroups(0, NULL);
2338                         if (srv->srvconf.username->used) {
2339 @@ -804,7 +806,7 @@
2340  #endif
2341  #ifdef HAVE_PWD_H
2342                 /* drop root privs */
2343 -               if (srv->srvconf.username->used) {
2344 +               if (NULL != pwd) {
2345                         setuid(pwd->pw_uid);
2346                 }
2347  #endif
2348 @@ -843,7 +845,7 @@
2349                 }
2350  
2351                 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
2352 -                       srv->max_fds = rlim.rlim_cur < FD_SETSIZE - 200 ? rlim.rlim_cur : FD_SETSIZE - 200;
2353 +                       srv->max_fds = rlim.rlim_cur < ((int)FD_SETSIZE) - 200 ? rlim.rlim_cur : FD_SETSIZE - 200;
2354                 } else {
2355                         srv->max_fds = rlim.rlim_cur;
2356                 }
2357 @@ -857,7 +859,7 @@
2358  #endif
2359                 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
2360                         /* don't raise the limit above FD_SET_SIZE */
2361 -                       if (srv->max_fds > FD_SETSIZE - 200) {
2362 +                       if (srv->max_fds > ((int)FD_SETSIZE) - 200) {
2363                                 log_error_write(srv, __FILE__, __LINE__, "sd",
2364                                                 "can't raise max filedescriptors above",  FD_SETSIZE - 200,
2365                                                 "if event-handler is 'select'. Use 'poll' or something else or reduce server.max-fds.");
2366 Index: src/mod_dirlisting.c
2367 ===================================================================
2368 --- src/mod_dirlisting.c        (.../tags/lighttpd-1.4.23)
2369 +++ src/mod_dirlisting.c        (.../branches/lighttpd-1.4.x)
2370 @@ -198,7 +198,7 @@
2371         data_unset *du;
2372  
2373         if (NULL != (du = array_get_element(ca, option))) {
2374 -               data_array *da = (data_array *)du;
2375 +               data_array *da;
2376                 size_t j;
2377  
2378                 if (du->type != TYPE_ARRAY) {
2379 Index: src/mod_magnet.c
2380 ===================================================================
2381 --- src/mod_magnet.c    (.../tags/lighttpd-1.4.23)
2382 +++ src/mod_magnet.c    (.../branches/lighttpd-1.4.x)
2383 @@ -283,17 +283,11 @@
2384  }
2385  
2386  static int magnet_reqhdr_get(lua_State *L) {
2387 -       server *srv;
2388         connection *con;
2389         data_string *ds;
2390  
2391         const char *key = luaL_checkstring(L, 2);
2392  
2393 -       lua_pushstring(L, "lighty.srv");
2394 -       lua_gettable(L, LUA_REGISTRYINDEX);
2395 -       srv = lua_touserdata(L, -1);
2396 -       lua_pop(L, 1);
2397 -
2398         lua_pushstring(L, "lighty.con");
2399         lua_gettable(L, LUA_REGISTRYINDEX);
2400         con = lua_touserdata(L, -1);
2401 Index: src/log.c
2402 ===================================================================
2403 --- src/log.c   (.../tags/lighttpd-1.4.23)
2404 +++ src/log.c   (.../branches/lighttpd-1.4.x)
2405 @@ -62,7 +62,6 @@
2406                 /* create write pipe and spawn process */
2407  
2408                 int to_log_fds[2];
2409 -               pid_t pid;
2410  
2411                 if (pipe(to_log_fds)) {
2412                         log_error_write(srv, __FILE__, __LINE__, "ss", "pipe failed: ", strerror(errno));
2413 @@ -70,7 +69,7 @@
2414                 }
2415  
2416                 /* fork, execve */
2417 -               switch (pid = fork()) {
2418 +               switch (fork()) {
2419                 case 0:
2420                         /* child */
2421                         close(STDIN_FILENO);
2422 @@ -150,14 +149,14 @@
2423   */
2424  
2425  int log_error_open(server *srv) {
2426 -       int close_stderr = 1;
2427 -
2428  #ifdef HAVE_SYSLOG_H
2429         /* perhaps someone wants to use syslog() */
2430         openlog("lighttpd", LOG_CONS | LOG_PID, LOG_DAEMON);
2431  #endif
2432 -       srv->errorlog_mode = ERRORLOG_STDERR;
2433  
2434 +       srv->errorlog_mode = ERRORLOG_FD;
2435 +       srv->errorlog_fd = STDERR_FILENO;
2436 +
2437         if (srv->srvconf.errorlog_use_syslog) {
2438                 srv->errorlog_mode = ERRORLOG_SYSLOG;
2439         } else if (!buffer_is_empty(srv->srvconf.errorlog_file)) {
2440 @@ -171,20 +170,36 @@
2441  
2442         log_error_write(srv, __FILE__, __LINE__, "s", "server started");
2443  
2444 -#ifdef HAVE_VALGRIND_VALGRIND_H
2445 -       /* don't close stderr for debugging purposes if run in valgrind */
2446 -       if (RUNNING_ON_VALGRIND) close_stderr = 0;
2447 -#endif
2448 -
2449 -       if (srv->errorlog_mode == ERRORLOG_STDERR && srv->srvconf.dont_daemonize) {
2450 +       if (srv->errorlog_mode == ERRORLOG_FD && !srv->srvconf.dont_daemonize) {
2451                 /* We can only log to stderr in dont-daemonize mode;
2452                  * if we do daemonize and no errorlog file is specified, we log into /dev/null
2453                  */
2454 -               close_stderr = 0;
2455 +               srv->errorlog_fd = -1;
2456         }
2457  
2458 -       /* move stderr to /dev/null */
2459 -       if (close_stderr) openDevNull(STDERR_FILENO);
2460 +       if (!buffer_is_empty(srv->srvconf.breakagelog_file)) {
2461 +               int breakage_fd;
2462 +               const char *logfile = srv->srvconf.breakagelog_file->ptr;
2463 +
2464 +               if (srv->errorlog_mode == ERRORLOG_FD) {
2465 +                       srv->errorlog_fd = dup(STDERR_FILENO);
2466 +#ifdef FD_CLOEXEC
2467 +                       fcntl(srv->errorlog_fd, F_SETFD, FD_CLOEXEC);
2468 +#endif
2469 +               }
2470 +
2471 +               if (-1 == (breakage_fd = open_logfile_or_pipe(srv, logfile))) {
2472 +                       return -1;
2473 +               }
2474 +
2475 +               if (STDERR_FILENO != breakage_fd) {
2476 +                       dup2(breakage_fd, STDERR_FILENO);
2477 +                       close(breakage_fd);
2478 +               }
2479 +       } else if (!srv->srvconf.dont_daemonize) {
2480 +               /* move stderr to /dev/null */
2481 +               openDevNull(STDERR_FILENO);
2482 +       }
2483         return 0;
2484  }
2485  
2486 @@ -235,15 +250,19 @@
2487         switch(srv->errorlog_mode) {
2488         case ERRORLOG_PIPE:
2489         case ERRORLOG_FILE:
2490 -               close(srv->errorlog_fd);
2491 +       case ERRORLOG_FD:
2492 +               if (-1 != srv->errorlog_fd) {
2493 +                       /* don't close STDERR */
2494 +                       if (STDERR_FILENO != srv->errorlog_fd)
2495 +                               close(srv->errorlog_fd);
2496 +                       srv->errorlog_fd = -1;
2497 +               }
2498                 break;
2499         case ERRORLOG_SYSLOG:
2500  #ifdef HAVE_SYSLOG_H
2501                 closelog();
2502  #endif
2503                 break;
2504 -       case ERRORLOG_STDERR:
2505 -               break;
2506         }
2507  
2508         return 0;
2509 @@ -255,7 +274,8 @@
2510         switch(srv->errorlog_mode) {
2511         case ERRORLOG_PIPE:
2512         case ERRORLOG_FILE:
2513 -       case ERRORLOG_STDERR:
2514 +       case ERRORLOG_FD:
2515 +               if (-1 == srv->errorlog_fd) return 0;
2516                 /* cache the generated timestamp */
2517                 if (srv->cur_ts != srv->last_generated_debug_ts) {
2518                         buffer_prepare_copy(srv->ts_debug_str, 255);
2519 @@ -349,13 +369,10 @@
2520         switch(srv->errorlog_mode) {
2521         case ERRORLOG_PIPE:
2522         case ERRORLOG_FILE:
2523 +       case ERRORLOG_FD:
2524                 buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("\n"));
2525                 write(srv->errorlog_fd, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
2526                 break;
2527 -       case ERRORLOG_STDERR:
2528 -               buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("\n"));
2529 -               write(STDERR_FILENO, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
2530 -               break;
2531         case ERRORLOG_SYSLOG:
2532                 syslog(LOG_ERR, "%s", srv->errorlog_buf->ptr);
2533                 break;
2534 Index: src/proc_open.c
2535 ===================================================================
2536 --- src/proc_open.c     (.../tags/lighttpd-1.4.23)
2537 +++ src/proc_open.c     (.../branches/lighttpd-1.4.x)
2538 @@ -309,6 +309,14 @@
2539  
2540         if (err) {
2541                 proc_read_fd_to_buffer(proc.err.fd, err);
2542 +       } else {
2543 +               buffer *tmp = buffer_init();
2544 +               proc_read_fd_to_buffer(proc.err.fd, tmp);
2545 +               if (tmp->used > 0 &&  write(2, (void*)tmp->ptr, tmp->used) < 0) {
2546 +                       perror("error writing pipe");
2547 +                       return -1;
2548 +               }
2549 +               buffer_free(tmp);
2550         }
2551         pipe_close(&proc.err);
2552  
2553 Index: tests/.cvsignore
2554 ===================================================================
2555 Index: tests/bug-12.conf
2556 ===================================================================
2557 --- tests/bug-12.conf   (.../tags/lighttpd-1.4.23)
2558 +++ tests/bug-12.conf   (.../branches/lighttpd-1.4.x)
2559 @@ -8,6 +8,7 @@
2560  ## bind to localhost (default: all interfaces)
2561  server.bind                = "localhost"
2562  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2563 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2564  server.name                = "www.example.org"
2565  server.tag                 = "Apache 1.3.29"
2566  
2567 Index: tests/fastcgi-10.conf
2568 ===================================================================
2569 --- tests/fastcgi-10.conf       (.../tags/lighttpd-1.4.23)
2570 +++ tests/fastcgi-10.conf       (.../branches/lighttpd-1.4.x)
2571 @@ -6,6 +6,7 @@
2572  ## bind to localhost (default: all interfaces)
2573  server.bind                = "localhost"
2574  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2575 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2576  server.name                = "www.example.org"
2577  server.tag                 = "Apache 1.3.29"
2578  
2579 Index: tests/bug-06.conf
2580 ===================================================================
2581 --- tests/bug-06.conf   (.../tags/lighttpd-1.4.23)
2582 +++ tests/bug-06.conf   (.../branches/lighttpd-1.4.x)
2583 @@ -8,6 +8,7 @@
2584  ## bind to localhost (default: all interfaces)
2585  server.bind                = "localhost"
2586  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2587 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2588  server.name                = "www.example.org"
2589  server.tag                 = "Apache 1.3.29"
2590  
2591 Index: tests/mod-extforward.conf
2592 ===================================================================
2593 Index: tests/var-include.conf
2594 ===================================================================
2595 --- tests/var-include.conf      (.../tags/lighttpd-1.4.23)
2596 +++ tests/var-include.conf      (.../branches/lighttpd-1.4.x)
2597 @@ -10,6 +10,7 @@
2598  ## bind to localhost (default: all interfaces)
2599  server.bind                = "localhost"
2600  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2601 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2602  server.name                = "www.example.org"
2603  server.tag                 = "Apache 1.3.29"
2604  
2605 Index: tests/404-handler.conf
2606 ===================================================================
2607 --- tests/404-handler.conf      (.../tags/lighttpd-1.4.23)
2608 +++ tests/404-handler.conf      (.../branches/lighttpd-1.4.x)
2609 @@ -10,6 +10,7 @@
2610  ## bind to localhost (default: all interfaces)
2611  server.bind                = "localhost"
2612  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2613 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2614  server.name                = "www.example.org"
2615  server.tag                 = "Apache 1.3.29"
2616  
2617 Index: tests/lowercase.conf
2618 ===================================================================
2619 --- tests/lowercase.conf        (.../tags/lighttpd-1.4.23)
2620 +++ tests/lowercase.conf        (.../branches/lighttpd-1.4.x)
2621 @@ -6,6 +6,7 @@
2622  ## bind to localhost (default: all interfaces)
2623  server.bind                = "localhost"
2624  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2625 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2626  
2627  server.force-lowercase-filenames = "enable"
2628  
2629 Index: tests/condition.conf
2630 ===================================================================
2631 --- tests/condition.conf        (.../tags/lighttpd-1.4.23)
2632 +++ tests/condition.conf        (.../branches/lighttpd-1.4.x)
2633 @@ -10,6 +10,7 @@
2634  ## bind to localhost (default: all interfaces)
2635  server.bind                = "localhost"
2636  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2637 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2638  server.name                = "www.example.org"
2639  server.tag                 = "Apache 1.3.29"
2640  
2641 Index: tests/fastcgi-13.conf
2642 ===================================================================
2643 --- tests/fastcgi-13.conf       (.../tags/lighttpd-1.4.23)
2644 +++ tests/fastcgi-13.conf       (.../branches/lighttpd-1.4.x)
2645 @@ -10,6 +10,7 @@
2646  ## bind to localhost (default: all interfaces)
2647  server.bind                = "localhost"
2648  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2649 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2650  server.name                = "www.example.org"
2651  server.tag                 = "Apache 1.3.29"
2652  
2653 Index: tests/mod-compress.conf
2654 ===================================================================
2655 --- tests/mod-compress.conf     (.../tags/lighttpd-1.4.23)
2656 +++ tests/mod-compress.conf     (.../branches/lighttpd-1.4.x)
2657 @@ -11,6 +11,7 @@
2658  ## bind to localhost (default: all interfaces)
2659  server.bind                = "localhost"
2660  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2661 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2662  server.name                = "www.example.org"
2663  
2664  server.modules = (
2665 Index: tests/lighttpd.conf
2666 ===================================================================
2667 --- tests/lighttpd.conf (.../tags/lighttpd-1.4.23)
2668 +++ tests/lighttpd.conf (.../branches/lighttpd-1.4.x)
2669 @@ -13,6 +13,7 @@
2670  ## bind to localhost (default: all interfaces)
2671  server.bind                = "localhost"
2672  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2673 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2674  server.name                = "www.example.org"
2675  server.tag                 = "Apache 1.3.29"
2676  
2677 Index: tests/fastcgi-responder.conf
2678 ===================================================================
2679 --- tests/fastcgi-responder.conf        (.../tags/lighttpd-1.4.23)
2680 +++ tests/fastcgi-responder.conf        (.../branches/lighttpd-1.4.x)
2681 @@ -15,6 +15,7 @@
2682  ## bind to localhost (default: all interfaces)
2683  server.bind                = "localhost"
2684  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2685 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2686  server.name                = "www.example.org"
2687  server.tag                 = "Apache 1.3.29"
2688  
2689 Index: tests/fastcgi-auth.conf
2690 ===================================================================
2691 --- tests/fastcgi-auth.conf     (.../tags/lighttpd-1.4.23)
2692 +++ tests/fastcgi-auth.conf     (.../branches/lighttpd-1.4.x)
2693 @@ -12,6 +12,7 @@
2694  ## bind to localhost (default: all interfaces)
2695  server.bind                = "localhost"
2696  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2697 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2698  server.name                = "www.example.org"
2699  server.tag                 = "Apache 1.3.29"
2700  
2701 Index: tests/proxy.conf
2702 ===================================================================
2703 --- tests/proxy.conf    (.../tags/lighttpd-1.4.23)
2704 +++ tests/proxy.conf    (.../branches/lighttpd-1.4.x)
2705 @@ -6,6 +6,7 @@
2706  ## bind to localhost (default: all interfaces)
2707  server.bind                = "localhost"
2708  server.errorlog            = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
2709 +server.breakagelog         = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
2710  server.name                = "www.example.org"
2711  server.tag                 = "Proxy"
2712  
2713 Index: tests/LightyTest.pm
2714 ===================================================================
2715 --- tests/LightyTest.pm (.../tags/lighttpd-1.4.23)
2716 +++ tests/LightyTest.pm (.../branches/lighttpd-1.4.x)
2717 @@ -87,14 +87,21 @@
2718         my $self = shift;
2719         my $port = shift;
2720         my $child = shift;
2721 +       my $timeout = 5*10; # 5 secs, select waits 0.1 s
2722  
2723         while (0 == $self->listening_on($port)) {
2724                 select(undef, undef, undef, 0.1);
2725 +               $timeout--;
2726  
2727                 # the process is gone, we failed
2728                 if (0 != waitpid($child, WNOHANG)) {
2729                         return -1;
2730                 }
2731 +               if (0 >= $timeout) {
2732 +                       diag("Timeout while trying to connect; killing child");
2733 +                       kill('TERM', $child);
2734 +                       return -1;
2735 +               }
2736         }
2737  
2738         return 0;
2739 Index: configure.ac
2740 ===================================================================
2741 --- configure.ac        (.../tags/lighttpd-1.4.23)
2742 +++ configure.ac        (.../branches/lighttpd-1.4.x)
2743 @@ -1,9 +1,10 @@
2744  #                                               -*- Autoconf -*-
2745  # Process this file with autoconf to produce a configure script.
2746  AC_PREREQ(2.57)
2747 -AC_INIT([lighttpd], [1.4.23], [contact@lighttpd.net])
2748 +AC_INIT([lighttpd], [1.4.24], [contact@lighttpd.net])
2749  AC_CONFIG_SRCDIR([src/server.c])
2750  AC_CONFIG_HEADER([config.h])
2751 +AC_CONFIG_MACRO_DIR([m4])
2752  
2753  AC_CANONICAL_TARGET
2754  
2755 @@ -417,12 +418,18 @@
2756     AC_DEFINE([HAVE_LUA], [1], [liblua])
2757     AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
2758   ],[
2759 -   # for debian based systems
2760 -   PKG_CHECK_MODULES(LUA, lua5.1 >= 5.1, [
2761 -     AC_DEFINE([HAVE_LUA], [1], [liblua])
2762 -     AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
2763 -   ])
2764 + # for debian based systems
2765 + PKG_CHECK_MODULES(LUA, lua5.1 >= 5.1, [
2766 +   AC_DEFINE([HAVE_LUA], [1], [liblua])
2767 +   AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
2768 + ],[
2769 + # for freebsd
2770 + PKG_CHECK_MODULES(LUA, lua-5.1 >= 5.1, [
2771 +   AC_DEFINE([HAVE_LUA], [1], [liblua])
2772 +   AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
2773   ])
2774 + ])
2775 + ])
2776  
2777   AC_SUBST(LUA_CFLAGS)
2778   AC_SUBST(LUA_LIBS)
2779 Index: doc/.cvsignore
2780 ===================================================================
2781 Index: doc/fastcgi.txt
2782 ===================================================================
2783 --- doc/fastcgi.txt     (.../tags/lighttpd-1.4.23)
2784 +++ doc/fastcgi.txt     (.../branches/lighttpd-1.4.x)
2785 @@ -95,23 +95,22 @@
2786        (
2787          ( "host" => <string> ,
2788            "port" => <integer> ,
2789 -         "socket" => <string>,       # either socket
2790 -                                     # or host+port
2791 -         "bin-path" => <string>,     # OPTIONAL
2792 -         "bin-environment" => <array>, # OPTIONAL
2793 -         "bin-copy-environment" => <array>, # OPTIONAL
2794 +          "socket" => <string>,       # either socket
2795 +                                      # or host+port
2796 +          "bin-path" => <string>,     # OPTIONAL
2797 +          "bin-environment" => <array>, # OPTIONAL
2798 +          "bin-copy-environment" => <array>, # OPTIONAL
2799            "mode" => <string>,         # OPTIONAL
2800            "docroot" => <string> ,     # OPTIONAL if "mode"
2801 -                                     # is not "authorizer"
2802 +                                      # is not "authorizer"
2803            "check-local" => <string>,  # OPTIONAL
2804 -         "min-procs" => <integer>,   # OPTIONAL
2805 -         "max-procs" => <integer>,   # OPTIONAL
2806 -         "max-load-per-proc" => <integer>, # OPTIONAL
2807 -         "idle-timeout" => <integer>, # OPTIONAL
2808 -         "broken-scriptfilename" => <boolean>, # OPTIONAL
2809 +          "max-procs" => <integer>,   # OPTIONAL
2810 +          "broken-scriptfilename" => <boolean>, # OPTIONAL
2811            "disable-time" => <integer>, # optional
2812 -          "allow-x-send-file" => <boolean> # optional
2813 -       ),
2814 +          "allow-x-send-file" => <boolean>, # optional
2815 +          "kill-signal" => <integer>, # OPTIONAL
2816 +          "fix-root-scriptname" => <boolean>,
2817 +                                      # OPTIONAL
2818          ( "host" => ...
2819          )
2820        )
2821 @@ -127,42 +126,38 @@
2822    :"socket":    path to the unix-domain socket
2823    :"mode":      is the FastCGI protocol mode.
2824                  Default is "responder", also "authorizer"
2825 -               mode is implemented.
2826 +                mode is implemented.
2827    :"docroot":   is optional and is the docroot on the remote
2828                  host for default "responder" mode. For
2829 -               "authorizer" mode it is MANDATORY and it points
2830 -               to docroot for authorized requests. For security
2831 -               reasons it is recommended to keep this docroot
2832 +                "authorizer" mode it is MANDATORY and it points
2833 +                to docroot for authorized requests. For security
2834 +                reasons it is recommended to keep this docroot
2835                  outside of server.document-root tree.
2836    :"check-local": is optional and may be "enable" (default) or
2837                  "disable". If enabled the server first check
2838 -               for a file in local server.document-root tree
2839 -               and return 404 (Not Found) if no such file.
2840 +                for a file in local server.document-root tree
2841 +                and return 404 (Not Found) if no such file.
2842                  If disabled, the server forward request to
2843 -               FastCGI interface without this check.
2844 +                FastCGI interface without this check.
2845    :"broken-scriptfilename": breaks SCRIPT_FILENAME in a wat that
2846                  PHP can extract PATH_INFO from it (default: disabled)
2847    :"disable-time": time to wait before a disabled backend is checked
2848                  again
2849    :"allow-x-send-file": controls if X-LIGHTTPD-send-file headers
2850                  are allowed
2851 +  :"fix-root-scriptname": fix broken path-info split for "/" extension ("prefix")
2852  
2853    If bin-path is set:
2854  
2855 -  :"min-procs": sets the minium processes to start
2856    :"max-procs": the upper limit of the processess to start
2857 -  :"max-load-per-proc": maximum number of waiting processes on
2858 -                average per process before a new process is
2859 -                spawned
2860 -  :"idle-timeout": number of seconds before a unused process
2861 -                gets terminated
2862    :"bin-environment": put an entry into the environment of
2863                  the started process
2864    :"bin-copy-environement": clean up the environment and copy
2865                  only the specified entries into the fresh
2866                  environment of the spawn process
2867 +  :"kill-signal": signal to terminate the FastCGI process with,
2868 +                defauls to SIGTERM
2869  
2870 -
2871  Examples
2872  --------
2873  
2874 @@ -171,11 +166,11 @@
2875      fastcgi.server = ( ".php" =>
2876        (( "host" => "127.0.0.1",
2877           "port" => 1026,
2878 -        "bin-path" => "/usr/local/bin/php"
2879 +         "bin-path" => "/usr/local/bin/php"
2880        )),
2881        ".php4" =>
2882        (( "host" => "127.0.0.1",
2883 -        "port" => 1026
2884 +         "port" => 1026
2885        ))
2886      )
2887  
2888 @@ -183,10 +178,10 @@
2889  
2890      fastcgi.server = ( "/remote_scripts/" =>
2891        (( "host" => "192.168.0.3",
2892 -        "port" => 9000,
2893 +         "port" => 9000,
2894           "check-local" => "disable",
2895           "docroot" => "/" # remote server may use
2896 -                         # it's own docroot
2897 +                          # it's own docroot
2898        ))
2899      )
2900  
2901 @@ -206,7 +201,7 @@
2902  
2903      fastcgi.server = ( "/remote_scripts/" =>
2904        (( "host" => "10.0.0.2",
2905 -        "port" => 9000,
2906 +         "port" => 9000,
2907           "docroot" => "/path_to_private_docs",
2908           "mode" => "authorizer"
2909        ))
2910 @@ -318,10 +313,10 @@
2911       $ PHP_FCGI_CHILDREN=384 ./lighttpd -f ./lighttpd.conf
2912  
2913       fastcgi.server = ( ".php" =>
2914 -       (( "socket" => "/tmp/php.socket",
2915 +        (( "socket" => "/tmp/php.socket",
2916             "bin-path" => "/usr/local/bin/php",
2917             "min-procs" => 1,
2918 -          "max-procs" => 1,
2919 +           "max-procs" => 1,
2920             "max-load-per-proc" => 4,
2921             "idle-timeout" => 20
2922          ))
2923 @@ -408,7 +403,7 @@
2924             "PHP_FCGI_CHILDREN" => "16",
2925             "PHP_FCGI_MAX_REQUESTS" => "10000" ),
2926          "bin-copy-environment" => (
2927 -          "PATH", "SHELL", "USER" )
2928 +           "PATH", "SHELL", "USER" )
2929       ))
2930     )
2931  
2932 Index: SConstruct
2933 ===================================================================
2934 Index: Makefile.am
2935 ===================================================================
2936 --- Makefile.am (.../tags/lighttpd-1.4.23)
2937 +++ Makefile.am (.../branches/lighttpd-1.4.x)
2938 @@ -2,4 +2,6 @@
2939  
2940  EXTRA_DIST=autogen.sh SConstruct
2941  
2942 +ACLOCAL_AMFLAGS = -I m4
2943 +
2944  distcleancheck_listfiles = find -type f -exec sh -c 'test -f $(srcdir)/{} || echo {}' ';'
2945 Index: autogen.sh
2946 ===================================================================
2947 --- autogen.sh  (.../tags/lighttpd-1.4.23)
2948 +++ autogen.sh  (.../branches/lighttpd-1.4.x)
2949 @@ -1,27 +1,92 @@
2950  #!/bin/sh
2951  # Run this to generate all the initial makefiles, etc.
2952  
2953 -LIBTOOLIZE=${LIBTOOLIZE:-libtoolize}
2954  LIBTOOLIZE_FLAGS="--copy --force"
2955 -ACLOCAL=${ACLOCAL:-aclocal}
2956 -AUTOHEADER=${AUTOHEADER:-autoheader}
2957 -AUTOMAKE=${AUTOMAKE:-automake}
2958 -AUTOMAKE_FLAGS="--add-missing --copy"
2959 -AUTOCONF=${AUTOCONF:-autoconf}
2960 +AUTOMAKE_FLAGS="--add-missing --copy --foreign"
2961  
2962  ARGV0=$0
2963 +ARGS="$@"
2964  
2965 -set -e
2966  
2967 -
2968  run() {
2969 -       echo "$ARGV0: running \`$@'"
2970 -       $@
2971 +       echo "$ARGV0: running \`$@' $ARGS"
2972 +       $@ $ARGS
2973  }
2974  
2975 +## jump out if one of the programs returns 'false'
2976 +set -e
2977 +
2978 +## on macosx glibtoolize, others have libtool
2979 +if test x$LIBTOOLIZE = x; then
2980 +  if test \! "x`which glibtoolize 2> /dev/null | grep -v '^no'`" = x; then
2981 +    LIBTOOLIZE=glibtoolize
2982 +  elif test \! "x`which libtoolize-1.5 2> /dev/null | grep -v '^no'`" = x; then
2983 +    LIBTOOLIZE=libtoolize-1.5
2984 +  elif test \! "x`which libtoolize 2> /dev/null | grep -v '^no'`" = x; then
2985 +    LIBTOOLIZE=libtoolize
2986 +  else 
2987 +    echo "libtoolize 1.5.x wasn't found, exiting"; exit 0
2988 +  fi
2989 +fi
2990 +
2991 +## suse has aclocal and aclocal-1.9
2992 +if test x$ACLOCAL = x; then
2993 +  if test \! "x`which aclocal-1.9 2> /dev/null | grep -v '^no'`" = x; then
2994 +    ACLOCAL=aclocal-1.9
2995 +  elif test \! "x`which aclocal19 2> /dev/null | grep -v '^no'`" = x; then
2996 +    ACLOCAL=aclocal19
2997 +  elif test \! "x`which aclocal 2> /dev/null | grep -v '^no'`" = x; then
2998 +    ACLOCAL=aclocal
2999 +  else 
3000 +    echo "automake 1.9.x (aclocal) wasn't found, exiting"; exit 0
3001 +  fi
3002 +fi
3003 +
3004 +if test x$AUTOMAKE = x; then
3005 +  if test \! "x`which automake-1.9 2> /dev/null | grep -v '^no'`" = x; then
3006 +    AUTOMAKE=automake-1.9
3007 +  elif test \! "x`which automake19 2> /dev/null | grep -v '^no'`" = x; then
3008 +    AUTOMAKE=automake19
3009 +  elif test \! "x`which automake 2> /dev/null | grep -v '^no'`" = x; then
3010 +    AUTOMAKE=automake
3011 +  else 
3012 +    echo "automake 1.9.x wasn't found, exiting"; exit 0
3013 +  fi
3014 +fi
3015 +
3016 +
3017 +## macosx has autoconf-2.59 and autoconf-2.60
3018 +if test x$AUTOCONF = x; then
3019 +  if test \! "x`which autoconf-2.59 2> /dev/null | grep -v '^no'`" = x; then
3020 +    AUTOCONF=autoconf-2.59
3021 +  elif test \! "x`which autoconf259 2> /dev/null | grep -v '^no'`" = x; then
3022 +    AUTOCONF=autoconf259
3023 +  elif test \! "x`which autoconf 2> /dev/null | grep -v '^no'`" = x; then
3024 +    AUTOCONF=autoconf
3025 +  else 
3026 +    echo "autoconf 2.59+ wasn't found, exiting"; exit 0
3027 +  fi
3028 +fi
3029 +
3030 +if test x$AUTOHEADER = x; then
3031 +  if test \! "x`which autoheader-2.59 2> /dev/null | grep -v '^no'`" = x; then
3032 +    AUTOHEADER=autoheader-2.59
3033 +  elif test \! "x`which autoheader259 2> /dev/null | grep -v '^no'`" = x; then
3034 +    AUTOHEADER=autoheader259
3035 +  elif test \! "x`which autoheader 2> /dev/null | grep -v '^no'`" = x; then
3036 +    AUTOHEADER=autoheader
3037 +  else 
3038 +    echo "autoconf 2.59+ (autoheader) wasn't found, exiting"; exit 0
3039 +  fi
3040 +fi
3041 +
3042 +mkdir -p m4
3043  run $LIBTOOLIZE $LIBTOOLIZE_FLAGS
3044 -run $ACLOCAL $ACLOCAL_FLAGS
3045 +run $ACLOCAL $ACLOCAL_FLAGS -I m4
3046  run $AUTOHEADER
3047  run $AUTOMAKE $AUTOMAKE_FLAGS
3048  run $AUTOCONF
3049 -echo "Now type './configure ...' and 'make' to compile."
3050 +
3051 +if test "$ARGS" = "" ; then
3052 +  echo "Now type './configure ...' and 'make' to compile."
3053 +fi
3054 Index: NEWS
3055 ===================================================================
3056 --- NEWS        (.../tags/lighttpd-1.4.23)
3057 +++ NEWS        (.../branches/lighttpd-1.4.x)
3058 @@ -3,7 +3,42 @@
3059  NEWS
3060  ====
3061  
3062 -- 1.4.23 -
3063 +- 1.4.24 -
3064 +  * Add T_CONFIG_INT for bigger integers from the config (needed for #1966)
3065 +  * Use unsigned int (and T_CONFIG_INT) for max_request_size
3066 +  * Use unsigned int for secdownload.timeout (fixes #1966)
3067 +  * Keep url/host values from connection to display information while keep-alive in mod_status (fixes #1202)
3068 +  * Add server.breakagelog, a "special" stderr (fixes #1863)
3069 +  * Fix config evaluation for debug.log-timeouts option (#1529)
3070 +  * Add "cgi.execute-x-only" to mod_cgi, requires +x for cgi scripts (fixes #2013)
3071 +  * Fix FD_SETSIZE comparision warnings
3072 +  * Add "lua-5.1" to searched pkg-config names for lua
3073 +  * Fix unused function webdav_lockdiscovery in mod_webdav
3074 +  * cmake: Fix crypt lib check
3075 +  * cmake: Add -export-dynamic to link flags, fixes build on FreeBSD
3076 +  * Set FD_CLOEXEC for bound sockets before pipe-logger forks (fixes #2026)
3077 +  * Reset ignored signals to SIG_DFL before exec() in fastcgi/scgi (fixes #2029)
3078 +  * Show "no uri specified -> 400" error only when "debug.log-request-header-on-error" is enabled (fixes #2030)
3079 +  * Fix hanging connection in mod_scgi (fixes #2024)
3080 +  * Allow digits in hostnames in more places (fixes #1148)
3081 +  * Use connection_reset instead of handle_request_done for cleanup callbacks
3082 +  * Change mod_expire to append Cache-Control instead of overwriting it (fixes #1997)
3083 +  * Allow all comparisons for $SERVER["socket"] - only bind for "=="
3084 +  * Remove strptime failed message (fixes #2031)
3085 +  * Fix issues found with clang analyzer
3086 +  * Try to fix server.tag issue with localized svnversion
3087 +  * Fix handling network-write return values (#2024)
3088 +  * Use disable-time in fastcgi for all disables after errors, default is 1sec (fixes #2040)
3089 +  * Remove adaptive spawning code from fastcgi (was disabled for a long time)
3090 +  * Allow mod_mysql_vhost to use stored procedures (fixes #2011, thx Ben Brown)
3091 +  * Fix ipv6 in mod_proxy (fixes #2043)
3092 +  * Print errors from include_shell to stderr
3093 +  * Set tm.tm_isdst = 0 before mktime() (fixes #2047)
3094 +  * Use linux-epoll by default if available (fixes #2021, thx Olaf van der Spek)
3095 +  * Print an error if you use too many captures in a regex pattern (fixes #2059)
3096 +  * Combine Cache-Control header value in mod_expire to existing HTTP header if header already added by other modules (fixes #2068)
3097 +
3098 +- 1.4.23 - 2009-06-19
3099    * Added some extra warning options in cmake and fix the resulting warnings (unused/static functions)
3100    * New lighttpd man page (moved it to section 8) (fixes #1875)
3101    * Create rrd file for empty rrdfile in mod_rrdtool (#1788)
3102 Index: CMakeLists.txt
3103 ===================================================================
This page took 2.99586 seconds and 4 git commands to generate.