comparison src/core/ngx_times.c @ 616:8214eaef3530 NGINX_0_9_6

nginx 0.9.6 *) Feature: the "map" directive supports regular expressions as value of the first parameter. *) Feature: $time_iso8601 access_log variable. Thanks to Michael Lustfield.
author Igor Sysoev <http://sysoev.ru>
date Mon, 21 Mar 2011 00:00:00 +0300
parents 7858d4f8dec4
children d0f7a625f27c
comparison
equal deleted inserted replaced
615:02221dcea723 616:8214eaef3530
25 volatile ngx_msec_t ngx_current_msec; 25 volatile ngx_msec_t ngx_current_msec;
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 volatile ngx_str_t ngx_cached_http_log_iso8601;
30 31
31 #if !(NGX_WIN32) 32 #if !(NGX_WIN32)
32 33
33 /* 34 /*
34 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore, 35 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
44 [sizeof("1970/09/28 12:00:00")]; 45 [sizeof("1970/09/28 12:00:00")];
45 static u_char cached_http_time[NGX_TIME_SLOTS] 46 static u_char cached_http_time[NGX_TIME_SLOTS]
46 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; 47 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")];
47 static u_char cached_http_log_time[NGX_TIME_SLOTS] 48 static u_char cached_http_log_time[NGX_TIME_SLOTS]
48 [sizeof("28/Sep/1970:12:00:00 +0600")]; 49 [sizeof("28/Sep/1970:12:00:00 +0600")];
50 static u_char cached_http_log_iso8601[NGX_TIME_SLOTS]
51 [sizeof("1970-09-28T12:00:00+06:00")];
49 52
50 53
51 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 54 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
52 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 55 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
53 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 56 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
56 ngx_time_init(void) 59 ngx_time_init(void)
57 { 60 {
58 ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1; 61 ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1;
59 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; 62 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; 63 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
64 ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1;
61 65
62 ngx_cached_time = &cached_time[0]; 66 ngx_cached_time = &cached_time[0];
63 67
64 ngx_time_update(); 68 ngx_time_update();
65 } 69 }
66 70
67 71
68 void 72 void
69 ngx_time_update(void) 73 ngx_time_update(void)
70 { 74 {
71 u_char *p0, *p1, *p2; 75 u_char *p0, *p1, *p2, *p3;
72 ngx_tm_t tm, gmt; 76 ngx_tm_t tm, gmt;
73 time_t sec; 77 time_t sec;
74 ngx_uint_t msec; 78 ngx_uint_t msec;
75 ngx_time_t *tp; 79 ngx_time_t *tp;
76 struct timeval tv; 80 struct timeval tv;
150 tm.ngx_tm_year, tm.ngx_tm_hour, 154 tm.ngx_tm_year, tm.ngx_tm_hour,
151 tm.ngx_tm_min, tm.ngx_tm_sec, 155 tm.ngx_tm_min, tm.ngx_tm_sec,
152 tp->gmtoff < 0 ? '-' : '+', 156 tp->gmtoff < 0 ? '-' : '+',
153 ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60)); 157 ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
154 158
159 p3 = &cached_http_log_iso8601[slot][0];
160
161 (void) ngx_sprintf(p3, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
162 tm.ngx_tm_year, tm.ngx_tm_mon,
163 tm.ngx_tm_mday, tm.ngx_tm_hour,
164 tm.ngx_tm_min, tm.ngx_tm_sec,
165 tp->gmtoff < 0 ? '-' : '+',
166 ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
167
155 168
156 ngx_memory_barrier(); 169 ngx_memory_barrier();
157 170
158 ngx_cached_time = tp; 171 ngx_cached_time = tp;
159 ngx_cached_http_time.data = p0; 172 ngx_cached_http_time.data = p0;
160 ngx_cached_err_log_time.data = p1; 173 ngx_cached_err_log_time.data = p1;
161 ngx_cached_http_log_time.data = p2; 174 ngx_cached_http_log_time.data = p2;
175 ngx_cached_http_log_iso8601.data = p3;
162 176
163 ngx_unlock(&ngx_time_lock); 177 ngx_unlock(&ngx_time_lock);
164 } 178 }
165 179
166 180