Mercurial > hg > nginx
comparison src/core/ngx_times.c @ 3475:ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
*) change ngx_time_update() interface
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 25 Mar 2010 09:10:10 +0000 |
parents | d4c4cfdffe30 |
children | 72c3edbd4dc8 |
comparison
equal
deleted
inserted
replaced
3474:d4c4cfdffe30 | 3475:ab353d7dc182 |
---|---|
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_HAVE_GETTIMEZONE) | 31 #if !(NGX_WIN32) |
32 | 32 |
33 /* | 33 /* |
34 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore, | 34 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore, |
35 * if ngx_time_update() is called by signal handler, it uses the cached | 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. | 36 * GMT offset value. Fortunately the value is changed only two times a year. |
37 */ | 37 */ |
38 | 38 |
39 static ngx_int_t cached_gmtoff; | 39 static ngx_int_t cached_gmtoff; |
40 #endif | 40 #endif |
59 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; |
60 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; |
61 | 61 |
62 ngx_cached_time = &cached_time[0]; | 62 ngx_cached_time = &cached_time[0]; |
63 | 63 |
64 ngx_time_update(0); | 64 ngx_time_update(); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 void | 68 void |
69 ngx_time_update(ngx_uint_t use_cached_gmtoff) | 69 ngx_time_update(void) |
70 { | 70 { |
71 u_char *p0, *p1, *p2; | 71 u_char *p0, *p1, *p2; |
72 ngx_tm_t tm, gmt; | 72 ngx_tm_t tm, gmt; |
73 time_t sec; | 73 time_t sec; |
74 ngx_uint_t msec; | 74 ngx_uint_t msec; |
118 #if (NGX_HAVE_GETTIMEZONE) | 118 #if (NGX_HAVE_GETTIMEZONE) |
119 | 119 |
120 tp->gmtoff = ngx_gettimezone(); | 120 tp->gmtoff = ngx_gettimezone(); |
121 ngx_gmtime(sec + tp->gmtoff * 60, &tm); | 121 ngx_gmtime(sec + tp->gmtoff * 60, &tm); |
122 | 122 |
123 #elif (NGX_HAVE_GMTOFF) | |
124 | |
125 ngx_localtime(sec, &tm); | |
126 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); | |
127 tp->gmtoff = cached_gmtoff; | |
128 | |
123 #else | 129 #else |
124 | 130 |
125 if (use_cached_gmtoff) { | 131 ngx_localtime(sec, &tm); |
126 ngx_gmtime(sec + cached_gmtoff * 60, &tm); | 132 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst); |
127 | |
128 } else { | |
129 ngx_localtime(sec, &tm); | |
130 | |
131 #if (NGX_HAVE_GMTOFF) | |
132 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); | |
133 #else | |
134 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst); | |
135 #endif | |
136 | |
137 } | |
138 | |
139 tp->gmtoff = cached_gmtoff; | 133 tp->gmtoff = cached_gmtoff; |
140 | 134 |
141 #endif | 135 #endif |
142 | 136 |
143 | 137 |
166 ngx_cached_err_log_time.data = p1; | 160 ngx_cached_err_log_time.data = p1; |
167 ngx_cached_http_log_time.data = p2; | 161 ngx_cached_http_log_time.data = p2; |
168 | 162 |
169 ngx_unlock(&ngx_time_lock); | 163 ngx_unlock(&ngx_time_lock); |
170 } | 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 | |
171 | 218 |
172 | 219 |
173 u_char * | 220 u_char * |
174 ngx_http_time(u_char *buf, time_t t) | 221 ngx_http_time(u_char *buf, time_t t) |
175 { | 222 { |