Klaus Demo nginx / 6d45d8a
*) introduce ngx_time_sigsafe_update() to update the error log time only *) change ngx_time_update() interface Igor Sysoev 12 years ago
17 changed file(s) with 97 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
6262 tp = ngx_timeofday();
6363 tp->sec = 0;
6464
65 ngx_time_update(0);
65 ngx_time_update();
6666
6767
6868 log = old_cycle->log;
2727 volatile ngx_str_t ngx_cached_http_time;
2828 volatile ngx_str_t ngx_cached_http_log_time;
2929
30 #if !(NGX_HAVE_GETTIMEZONE)
30 #if !(NGX_WIN32)
3131
3232 /*
3333 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
34 * if ngx_time_update() is called by signal handler, it uses the cached
34 * they must not be called by a signal handler, so we use the cached
3535 * GMT offset value. Fortunately the value is changed only two times a year.
3636 */
3737
6060
6161 ngx_cached_time = &cached_time[0];
6262
63 ngx_time_update(0);
63 ngx_time_update();
6464 }
6565
6666
6767 void
68 ngx_time_update(ngx_uint_t use_cached_gmtoff)
68 ngx_time_update(void)
6969 {
7070 u_char *p0, *p1, *p2;
7171 ngx_tm_t tm, gmt;
119119 tp->gmtoff = ngx_gettimezone();
120120 ngx_gmtime(sec + tp->gmtoff * 60, &tm);
121121
122 #elif (NGX_HAVE_GMTOFF)
123
124 ngx_localtime(sec, &tm);
125 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
126 tp->gmtoff = cached_gmtoff;
127
122128 #else
123129
124 if (use_cached_gmtoff) {
125 ngx_gmtime(sec + cached_gmtoff * 60, &tm);
126
127 } else {
128 ngx_localtime(sec, &tm);
129
130 #if (NGX_HAVE_GMTOFF)
131 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
132 #else
133 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
134 #endif
135
136 }
137
130 ngx_localtime(sec, &tm);
131 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
138132 tp->gmtoff = cached_gmtoff;
139133
140134 #endif
167161
168162 ngx_unlock(&ngx_time_lock);
169163 }
164
165
166 #if !(NGX_WIN32)
167
168 void
169 ngx_time_sigsafe_update(void)
170 {
171 u_char *p;
172 ngx_tm_t tm;
173 time_t sec;
174 ngx_uint_t msec;
175 ngx_time_t *tp;
176 struct timeval tv;
177
178 if (!ngx_trylock(&ngx_time_lock)) {
179 return;
180 }
181
182 ngx_gettimeofday(&tv);
183
184 sec = tv.tv_sec;
185 msec = tv.tv_usec / 1000;
186
187 tp = &cached_time[slot];
188
189 if (tp->sec == sec) {
190 ngx_unlock(&ngx_time_lock);
191 return;
192 }
193
194 if (slot == NGX_TIME_SLOTS - 1) {
195 slot = 0;
196 } else {
197 slot++;
198 }
199
200 ngx_gmtime(sec + cached_gmtoff * 60, &tm);
201
202 p = &cached_err_log_time[slot][0];
203
204 (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
205 tm.ngx_tm_year, tm.ngx_tm_mon,
206 tm.ngx_tm_mday, tm.ngx_tm_hour,
207 tm.ngx_tm_min, tm.ngx_tm_sec);
208
209 ngx_memory_barrier();
210
211 ngx_cached_err_log_time.data = p;
212
213 ngx_unlock(&ngx_time_lock);
214 }
215
216 #endif
170217
171218
172219 u_char *
1919
2020
2121 void ngx_time_init(void);
22 void ngx_time_update(ngx_uint_t use_cached_gmtoff);
22 void ngx_time_update(void);
23 void ngx_time_sigsafe_update(void);
2324 u_char *ngx_http_time(u_char *buf, time_t t);
2425 u_char *ngx_http_cookie_time(u_char *buf, time_t t);
2526 void ngx_gmtime(time_t t, ngx_tm_t *tp);
371371 err = (events == -1) ? ngx_errno : 0;
372372
373373 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
374 ngx_time_update(0);
374 ngx_time_update();
375375 }
376376
377377 if (err) {
531531 err = (events == -1) ? ngx_errno : 0;
532532
533533 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
534 ngx_time_update(0);
534 ngx_time_update();
535535 }
536536
537537 if (err) {
404404 err = ngx_errno;
405405
406406 if (flags & NGX_UPDATE_TIME) {
407 ngx_time_update(0);
407 ngx_time_update();
408408 }
409409
410410 if (n == -1) {
438438 for (i = 0; i < events; i++) {
439439
440440 if (event_list[i].portev_source == PORT_SOURCE_TIMER) {
441 ngx_time_update(0);
441 ngx_time_update();
442442 continue;
443443 }
444444
162162 for ( ;; ) {
163163 Sleep(timer);
164164
165 ngx_time_update(0);
165 ngx_time_update();
166166 #if 1
167167 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer");
168168 #endif
257257 delta = ngx_current_msec;
258258
259259 if (flags & NGX_UPDATE_TIME) {
260 ngx_time_update(0);
260 ngx_time_update();
261261 }
262262
263263 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
537537 err = (events == -1) ? ngx_errno : 0;
538538
539539 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
540 ngx_time_update(0);
540 ngx_time_update();
541541 }
542542
543543 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
588588 #if (NGX_HAVE_TIMER_EVENT)
589589
590590 if (event_list[i].filter == EVFILT_TIMER) {
591 ngx_time_update(0);
591 ngx_time_update();
592592 continue;
593593 }
594594
262262 err = (ready == -1) ? ngx_errno : 0;
263263
264264 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
265 ngx_time_update(0);
265 ngx_time_update();
266266 }
267267
268268 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
322322 "rtsig signo:%d", signo);
323323
324324 if (flags & NGX_UPDATE_TIME) {
325 ngx_time_update(0);
325 ngx_time_update();
326326 }
327327
328328 if (err == NGX_EAGAIN) {
348348 signo, si.si_fd, si.si_band);
349349
350350 if (flags & NGX_UPDATE_TIME) {
351 ngx_time_update(0);
351 ngx_time_update();
352352 }
353353
354354 rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
418418
419419 } else if (signo == SIGALRM) {
420420
421 ngx_time_update(0);
421 ngx_time_update();
422422
423423 return NGX_OK;
424424
670670 }
671671
672672 if (flags & NGX_UPDATE_TIME) {
673 ngx_time_update(0);
673 ngx_time_update();
674674 }
675675
676676 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
262262 err = (ready == -1) ? ngx_errno : 0;
263263
264264 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
265 ngx_time_update(0);
265 ngx_time_update();
266266 }
267267
268268 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
268268 err = (ready == -1) ? ngx_socket_errno : 0;
269269
270270 if (flags & NGX_UPDATE_TIME) {
271 ngx_time_update(0);
271 ngx_time_update();
272272 }
273273
274274 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
12151215
12161216 if (cache->files++ > 100) {
12171217
1218 ngx_time_update(0);
1218 ngx_time_update();
12191219
12201220 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
12211221
12321232
12331233 ngx_msleep(200);
12341234
1235 ngx_time_update(0);
1235 ngx_time_update();
12361236 }
12371237
12381238 cache->last = ngx_current_msec;
316316 }
317317 }
318318
319 ngx_time_update(1);
319 ngx_time_sigsafe_update();
320320
321321 action = "";
322322
167167
168168 sigsuspend(&set);
169169
170 ngx_time_update(0);
170 ngx_time_update();
171171
172172 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
173173 "wake up, sigio %i", sigio);
13411341
13421342 next = (n <= next) ? n : next;
13431343
1344 ngx_time_update(0);
1344 ngx_time_update();
13451345 }
13461346 }
13471347
13711371
13721372 if (path[i]->loader) {
13731373 path[i]->loader(path[i]->data);
1374 ngx_time_update(0);
1374 ngx_time_update();
13751375 }
13761376 }
13771377
8484
8585 rc = WaitForMultipleObjects(2, events, 0, 5000);
8686
87 ngx_time_update(0);
87 ngx_time_update();
8888
8989 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
9090 "WaitForMultipleObjects: %ul", rc);
139139 ev = WaitForMultipleObjects(nev, events, 0, timeout);
140140
141141 err = ngx_errno;
142 ngx_time_update(0);
142 ngx_time_update();
143143
144144 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
145145 "master WaitForMultipleObjects: %ul", ev);
678678 ev = WaitForMultipleObjects(3, events, 0, INFINITE);
679679
680680 err = ngx_errno;
681 ngx_time_update(0);
681 ngx_time_update();
682682
683683 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
684684 "worker WaitForMultipleObjects: %ul", ev);
737737 ev = WaitForMultipleObjects(nev, events, 0, INFINITE);
738738
739739 err = ngx_errno;
740 ngx_time_update(0);
740 ngx_time_update();
741741
742742 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
743743 "worker exit WaitForMultipleObjects: %ul", ev);
906906 ev = WaitForMultipleObjects(2, events, 0, INFINITE);
907907
908908 err = ngx_errno;
909 ngx_time_update(0);
909 ngx_time_update();
910910
911911 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
912912 "cache manager WaitForMultipleObjects: %ul", ev);
967967
968968 next = (n <= next) ? n : next;
969969
970 ngx_time_update(0);
970 ngx_time_update();
971971 }
972972 }
973973
979979
980980 if (ev != WAIT_TIMEOUT) {
981981
982 ngx_time_update(0);
982 ngx_time_update();
983983
984984 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
985985 "cache manager WaitForSingleObject: %ul", ev);
10071007
10081008 if (path[i]->loader) {
10091009 path[i]->loader(path[i]->data);
1010 ngx_time_update(0);
1010 ngx_time_update();
10111011 }
10121012 }
10131013