comparison src/core/ngx_times.c @ 579:be4f34123024 NGINX_0_8_35

nginx 0.8.35 *) Change: now the charset filter runs before the SSI filter. *) Feature: the "chunked_transfer_encoding" directive. *) Bugfix: an "&" character was not escaped when it was copied in arguments part in a rewrite rule. *) Bugfix: nginx might be terminated abnormally while a signal processing or if the directive "timer_resolution" was used on platforms which do not support kqueue or eventport notification methods. Thanks to George Xie and Maxim Dounin. *) Bugfix: if temporary files and permanent storage area resided at different file systems, then permanent file modification times were incorrect. Thanks to Maxim Dounin. *) Bugfix: ngx_http_memcached_module might issue the error message "memcached sent invalid trailer". Thanks to Maxim Dounin. *) Bugfix: nginx could not built zlib-1.2.4 library using the library sources. Thanks to Maxim Dounin. *) Bugfix: a segmentation fault occurred in a worker process, if there was large stderr output before FastCGI response; the bug had appeared in 0.8.34. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 29 Mar 2010 00:00:00 +0400
parents a094317ba307
children 7858d4f8dec4
comparison
equal deleted inserted replaced
577:dd7104f21940 579:be4f34123024
26 volatile ngx_time_t *ngx_cached_time; 26 volatile ngx_time_t *ngx_cached_time;
27 volatile ngx_str_t ngx_cached_err_log_time; 27 volatile ngx_str_t ngx_cached_err_log_time;
28 volatile ngx_str_t ngx_cached_http_time; 28 volatile ngx_str_t ngx_cached_http_time;
29 volatile ngx_str_t ngx_cached_http_log_time; 29 volatile ngx_str_t ngx_cached_http_log_time;
30 30
31 #if !(NGX_WIN32)
32
33 /*
34 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
35 * they must not be called by a signal handler, so we use the cached
36 * GMT offset value. Fortunately the value is changed only two times a year.
37 */
38
39 static ngx_int_t cached_gmtoff;
40 #endif
41
31 static ngx_time_t cached_time[NGX_TIME_SLOTS]; 42 static ngx_time_t cached_time[NGX_TIME_SLOTS];
32 static u_char cached_err_log_time[NGX_TIME_SLOTS] 43 static u_char cached_err_log_time[NGX_TIME_SLOTS]
33 [sizeof("1970/09/28 12:00:00")]; 44 [sizeof("1970/09/28 12:00:00")];
34 static u_char cached_http_time[NGX_TIME_SLOTS] 45 static u_char cached_http_time[NGX_TIME_SLOTS]
35 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; 46 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")];
48 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; 59 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
49 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1; 60 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
50 61
51 ngx_cached_time = &cached_time[0]; 62 ngx_cached_time = &cached_time[0];
52 63
53 ngx_time_update(0, 0); 64 ngx_time_update();
54 } 65 }
55 66
56 67
57 void 68 void
58 ngx_time_update(time_t sec, ngx_uint_t msec) 69 ngx_time_update(void)
59 { 70 {
60 u_char *p0, *p1, *p2; 71 u_char *p0, *p1, *p2;
61 ngx_tm_t tm, gmt; 72 ngx_tm_t tm, gmt;
73 time_t sec;
74 ngx_uint_t msec;
62 ngx_time_t *tp; 75 ngx_time_t *tp;
63 struct timeval tv; 76 struct timeval tv;
64 77
65 if (!ngx_trylock(&ngx_time_lock)) { 78 if (!ngx_trylock(&ngx_time_lock)) {
66 return; 79 return;
67 } 80 }
68 81
69 if (sec == 0) { 82 ngx_gettimeofday(&tv);
70 ngx_gettimeofday(&tv); 83
71 84 sec = tv.tv_sec;
72 sec = tv.tv_sec; 85 msec = tv.tv_usec / 1000;
73 msec = tv.tv_usec / 1000;
74 }
75 86
76 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; 87 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
77 88
78 tp = &cached_time[slot]; 89 tp = &cached_time[slot];
79 90
110 ngx_gmtime(sec + tp->gmtoff * 60, &tm); 121 ngx_gmtime(sec + tp->gmtoff * 60, &tm);
111 122
112 #elif (NGX_HAVE_GMTOFF) 123 #elif (NGX_HAVE_GMTOFF)
113 124
114 ngx_localtime(sec, &tm); 125 ngx_localtime(sec, &tm);
115 tp->gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); 126 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
127 tp->gmtoff = cached_gmtoff;
116 128
117 #else 129 #else
118 130
119 ngx_localtime(sec, &tm); 131 ngx_localtime(sec, &tm);
120 tp->gmtoff = ngx_timezone(tm.ngx_tm_isdst); 132 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
133 tp->gmtoff = cached_gmtoff;
121 134
122 #endif 135 #endif
123 136
124 137
125 p1 = &cached_err_log_time[slot][0]; 138 p1 = &cached_err_log_time[slot][0];
147 ngx_cached_err_log_time.data = p1; 160 ngx_cached_err_log_time.data = p1;
148 ngx_cached_http_log_time.data = p2; 161 ngx_cached_http_log_time.data = p2;
149 162
150 ngx_unlock(&ngx_time_lock); 163 ngx_unlock(&ngx_time_lock);
151 } 164 }
165
166
167 #if !(NGX_WIN32)
168
169 void
170 ngx_time_sigsafe_update(void)
171 {
172 u_char *p;
173 ngx_tm_t tm;
174 time_t sec;
175 ngx_uint_t msec;
176 ngx_time_t *tp;
177 struct timeval tv;
178
179 if (!ngx_trylock(&ngx_time_lock)) {
180 return;
181 }
182
183 ngx_gettimeofday(&tv);
184
185 sec = tv.tv_sec;
186 msec = tv.tv_usec / 1000;
187
188 tp = &cached_time[slot];
189
190 if (tp->sec == sec) {
191 ngx_unlock(&ngx_time_lock);
192 return;
193 }
194
195 if (slot == NGX_TIME_SLOTS - 1) {
196 slot = 0;
197 } else {
198 slot++;
199 }
200
201 ngx_gmtime(sec + cached_gmtoff * 60, &tm);
202
203 p = &cached_err_log_time[slot][0];
204
205 (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
206 tm.ngx_tm_year, tm.ngx_tm_mon,
207 tm.ngx_tm_mday, tm.ngx_tm_hour,
208 tm.ngx_tm_min, tm.ngx_tm_sec);
209
210 ngx_memory_barrier();
211
212 ngx_cached_err_log_time.data = p;
213
214 ngx_unlock(&ngx_time_lock);
215 }
216
217 #endif
152 218
153 219
154 u_char * 220 u_char *
155 ngx_http_time(u_char *buf, time_t t) 221 ngx_http_time(u_char *buf, time_t t)
156 { 222 {