summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-03-25 09:10:10 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-03-25 09:10:10 +0000
commit6d45d8a50da07591ed0de584bba1e526cc9b9406 (patch)
tree7ec3bc90902c6ddd64df14ee89e152cd452e229f /src/core
parent2f916a972139be74d437e40bdc7d236401123170 (diff)
downloadnginx-6d45d8a50da07591ed0de584bba1e526cc9b9406.tar.gz
nginx-6d45d8a50da07591ed0de584bba1e526cc9b9406.tar.bz2
*) introduce ngx_time_sigsafe_update() to update the error log time only
*) change ngx_time_update() interface
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ngx_cycle.c2
-rw-r--r--src/core/ngx_times.c79
-rw-r--r--src/core/ngx_times.h3
3 files changed, 66 insertions, 18 deletions
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 2c3dcc848..80caa1b35 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -63,7 +63,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
tp = ngx_timeofday();
tp->sec = 0;
- ngx_time_update(0);
+ ngx_time_update();
log = old_cycle->log;
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 94993e291..d9f5aa28e 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -28,11 +28,11 @@ volatile ngx_str_t ngx_cached_err_log_time;
volatile ngx_str_t ngx_cached_http_time;
volatile ngx_str_t ngx_cached_http_log_time;
-#if !(NGX_HAVE_GETTIMEZONE)
+#if !(NGX_WIN32)
/*
* locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
- * if ngx_time_update() is called by signal handler, it uses the cached
+ * they must not be called by a signal handler, so we use the cached
* GMT offset value. Fortunately the value is changed only two times a year.
*/
@@ -61,12 +61,12 @@ ngx_time_init(void)
ngx_cached_time = &cached_time[0];
- ngx_time_update(0);
+ ngx_time_update();
}
void
-ngx_time_update(ngx_uint_t use_cached_gmtoff)
+ngx_time_update(void)
{
u_char *p0, *p1, *p2;
ngx_tm_t tm, gmt;
@@ -120,22 +120,16 @@ ngx_time_update(ngx_uint_t use_cached_gmtoff)
tp->gmtoff = ngx_gettimezone();
ngx_gmtime(sec + tp->gmtoff * 60, &tm);
-#else
-
- if (use_cached_gmtoff) {
- ngx_gmtime(sec + cached_gmtoff * 60, &tm);
+#elif (NGX_HAVE_GMTOFF)
- } else {
- ngx_localtime(sec, &tm);
+ ngx_localtime(sec, &tm);
+ cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
+ tp->gmtoff = cached_gmtoff;
-#if (NGX_HAVE_GMTOFF)
- cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
#else
- cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
-#endif
-
- }
+ ngx_localtime(sec, &tm);
+ cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
tp->gmtoff = cached_gmtoff;
#endif
@@ -170,6 +164,59 @@ ngx_time_update(ngx_uint_t use_cached_gmtoff)
}
+#if !(NGX_WIN32)
+
+void
+ngx_time_sigsafe_update(void)
+{
+ u_char *p;
+ ngx_tm_t tm;
+ time_t sec;
+ ngx_uint_t msec;
+ ngx_time_t *tp;
+ struct timeval tv;
+
+ if (!ngx_trylock(&ngx_time_lock)) {
+ return;
+ }
+
+ ngx_gettimeofday(&tv);
+
+ sec = tv.tv_sec;
+ msec = tv.tv_usec / 1000;
+
+ tp = &cached_time[slot];
+
+ if (tp->sec == sec) {
+ ngx_unlock(&ngx_time_lock);
+ return;
+ }
+
+ if (slot == NGX_TIME_SLOTS - 1) {
+ slot = 0;
+ } else {
+ slot++;
+ }
+
+ ngx_gmtime(sec + cached_gmtoff * 60, &tm);
+
+ p = &cached_err_log_time[slot][0];
+
+ (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
+ tm.ngx_tm_year, tm.ngx_tm_mon,
+ tm.ngx_tm_mday, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec);
+
+ ngx_memory_barrier();
+
+ ngx_cached_err_log_time.data = p;
+
+ ngx_unlock(&ngx_time_lock);
+}
+
+#endif
+
+
u_char *
ngx_http_time(u_char *buf, time_t t)
{
diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h
index 4259d17d1..4e31f00a0 100644
--- a/src/core/ngx_times.h
+++ b/src/core/ngx_times.h
@@ -20,7 +20,8 @@ typedef struct {
void ngx_time_init(void);
-void ngx_time_update(ngx_uint_t use_cached_gmtoff);
+void ngx_time_update(void);
+void ngx_time_sigsafe_update(void);
u_char *ngx_http_time(u_char *buf, time_t t);
u_char *ngx_http_cookie_time(u_char *buf, time_t t);
void ngx_gmtime(time_t t, ngx_tm_t *tp);