annotate src/http/modules/ngx_http_not_modified_filter_module.c @ 3440:88741ec7731a stable-0.7

merge r3294, r3305: Fix a bug introduced in r2032: After a child process has read a terminate message from a channel, the process tries to read the channel again. The kernel (at least FreeBSD) may preempt the process and sends a SIGIO signal to a master process. The master process sends a new terminate message, the kernel switches again to the the child process, and the child process reads the messages instead of an EAGAIN error. And this may repeat over and over. Being that the child process can not exit the cycle and test the termination flag set by the message handler. The fix disallow the master process to send a new terminate message on SIGIO signal reception. It may send the message only on SIGALARM signal.
author Igor Sysoev <igor@sysoev.ru>
date Mon, 01 Feb 2010 15:49:36 +0000
parents eace65d6092b
children 793ae4dd91e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
4 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
5
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
13 static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
17 NULL, /* preconfiguration */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
18 ngx_http_not_modified_filter_init, /* postconfiguration */
177
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
19
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 NULL, /* create main configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 NULL, /* init main configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 NULL, /* create server configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 NULL, /* merge server configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 NULL, /* create location configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 NULL /* merge location configuration */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 };
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 ngx_module_t ngx_http_not_modified_filter_module = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
32 NGX_MODULE_V1,
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 &ngx_http_not_modified_filter_module_ctx, /* module context */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 NULL, /* module directives */
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 NGX_HTTP_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
36 NULL, /* init master */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
37 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
38 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
39 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
40 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
41 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
42 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
43 NGX_MODULE_V1_PADDING
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 };
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
47 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49
2702
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
50 static ngx_int_t
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
51 ngx_http_not_modified_header_filter(ngx_http_request_t *r)
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 {
2361
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
53 time_t ims;
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
54 ngx_http_core_loc_conf_t *clcf;
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 if (r->headers_out.status != NGX_HTTP_OK
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
57 || r != r->main
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 || r->headers_in.if_modified_since == NULL
142
cb77c084acdb nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents: 136
diff changeset
59 || r->headers_out.last_modified_time == -1)
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
61 return ngx_http_next_header_filter(r);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63
2496
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
64 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
65
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
66 if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) {
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
67 return ngx_http_next_header_filter(r);
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
68 }
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
69
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 r->headers_in.if_modified_since->value.len);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
72
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 195
diff changeset
73 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 195
diff changeset
74 "http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
2361
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
76 if (ims != r->headers_out.last_modified_time) {
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
77
2496
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
78 if (clcf->if_modified_since == NGX_HTTP_IMS_EXACT
2361
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
79 || ims < r->headers_out.last_modified_time)
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
80 {
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
81 return ngx_http_next_header_filter(r);
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
82 }
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84
2361
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
85 r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2496
diff changeset
86 r->headers_out.status_line.len = 0;
2361
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
87 r->headers_out.content_type.len = 0;
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
88 ngx_http_clear_content_length(r);
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
89 ngx_http_clear_accept_ranges(r);
c59485781f0a if_modified_since
Igor Sysoev <igor@sysoev.ru>
parents: 1631
diff changeset
90
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
91 return ngx_http_next_header_filter(r);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94
2702
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
95 static ngx_int_t
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
96 ngx_http_not_modified_filter_init(ngx_conf_t *cf)
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
98 ngx_http_next_header_filter = ngx_http_top_header_filter;
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 ngx_http_top_header_filter = ngx_http_not_modified_header_filter;
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 return NGX_OK;
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 }