*) introduce ngx_time_sigsafe_update() to update the error log time only
*) change ngx_time_update() interface
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 2c3dcc8..80caa1b 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -63,7 +63,7 @@
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 94993e2..d9f5aa2 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -28,11 +28,11 @@
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_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 @@
tp->gmtoff = ngx_gettimezone();
ngx_gmtime(sec + tp->gmtoff * 60, &tm);
+#elif (NGX_HAVE_GMTOFF)
+
+ ngx_localtime(sec, &tm);
+ cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
+ tp->gmtoff = cached_gmtoff;
+
#else
- if (use_cached_gmtoff) {
- ngx_gmtime(sec + cached_gmtoff * 60, &tm);
-
- } else {
- ngx_localtime(sec, &tm);
-
-#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 @@
}
+#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 4259d17..4e31f00 100644
--- a/src/core/ngx_times.h
+++ b/src/core/ngx_times.h
@@ -20,7 +20,8 @@
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);
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 3655eb9..e88c999 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -372,7 +372,7 @@
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err) {
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index 838573a..91fe1ec 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -532,7 +532,7 @@
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err) {
diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
index 8abf4d3..f4f0119 100644
--- a/src/event/modules/ngx_eventport_module.c
+++ b/src/event/modules/ngx_eventport_module.c
@@ -405,7 +405,7 @@
err = ngx_errno;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (n == -1) {
@@ -439,7 +439,7 @@
for (i = 0; i < events; i++) {
if (event_list[i].portev_source == PORT_SOURCE_TIMER) {
- ngx_time_update(0);
+ ngx_time_update();
continue;
}
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
index 5ce8674..3d63c31 100644
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -163,7 +163,7 @@
for ( ;; ) {
Sleep(timer);
- ngx_time_update(0);
+ ngx_time_update();
#if 1
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer");
#endif
@@ -258,7 +258,7 @@
delta = ngx_current_msec;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index e295d83..d78e562 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -538,7 +538,7 @@
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@@ -589,7 +589,7 @@
#if (NGX_HAVE_TIMER_EVENT)
if (event_list[i].filter == EVFILT_TIMER) {
- ngx_time_update(0);
+ ngx_time_update();
continue;
}
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index dc11d2e..ea947b7 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -263,7 +263,7 @@
err = (ready == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c
index a8cf4ab..4b01100 100644
--- a/src/event/modules/ngx_rtsig_module.c
+++ b/src/event/modules/ngx_rtsig_module.c
@@ -323,7 +323,7 @@
"rtsig signo:%d", signo);
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err == NGX_EAGAIN) {
@@ -349,7 +349,7 @@
signo, si.si_fd, si.si_band);
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
@@ -419,7 +419,7 @@
} else if (signo == SIGALRM) {
- ngx_time_update(0);
+ ngx_time_update();
return NGX_OK;
@@ -671,7 +671,7 @@
}
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 0ca5fac..72dbe74 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -263,7 +263,7 @@
err = (ready == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
diff --git a/src/event/modules/ngx_win32_select_module.c b/src/event/modules/ngx_win32_select_module.c
index 8a3264d..3d75d69 100644
--- a/src/event/modules/ngx_win32_select_module.c
+++ b/src/event/modules/ngx_win32_select_module.c
@@ -269,7 +269,7 @@
err = (ready == -1) ? ngx_socket_errno : 0;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index d24966f..aa6998b 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -1216,7 +1216,7 @@
if (cache->files++ > 100) {
- ngx_time_update(0);
+ ngx_time_update();
elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
@@ -1233,7 +1233,7 @@
ngx_msleep(200);
- ngx_time_update(0);
+ ngx_time_update();
}
cache->last = ngx_current_msec;
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index 4c41800..224101d 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -317,7 +317,7 @@
}
}
- ngx_time_update(1);
+ ngx_time_sigsafe_update();
action = "";
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 1804638..82d322d 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -168,7 +168,7 @@
sigsuspend(&set);
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"wake up, sigio %i", sigio);
@@ -1342,7 +1342,7 @@
next = (n <= next) ? n : next;
- ngx_time_update(0);
+ ngx_time_update();
}
}
@@ -1372,7 +1372,7 @@
if (path[i]->loader) {
path[i]->loader(path[i]->data);
- ngx_time_update(0);
+ ngx_time_update();
}
}
diff --git a/src/os/win32/ngx_process.c b/src/os/win32/ngx_process.c
index 08d9c0e..f4d372b 100644
--- a/src/os/win32/ngx_process.c
+++ b/src/os/win32/ngx_process.c
@@ -85,7 +85,7 @@
rc = WaitForMultipleObjects(2, events, 0, 5000);
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"WaitForMultipleObjects: %ul", rc);
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
index e4e92b8..5e9d32c 100644
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -140,7 +140,7 @@
ev = WaitForMultipleObjects(nev, events, 0, timeout);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"master WaitForMultipleObjects: %ul", ev);
@@ -679,7 +679,7 @@
ev = WaitForMultipleObjects(3, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
"worker WaitForMultipleObjects: %ul", ev);
@@ -738,7 +738,7 @@
ev = WaitForMultipleObjects(nev, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
"worker exit WaitForMultipleObjects: %ul", ev);
@@ -907,7 +907,7 @@
ev = WaitForMultipleObjects(2, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"cache manager WaitForMultipleObjects: %ul", ev);
@@ -968,7 +968,7 @@
next = (n <= next) ? n : next;
- ngx_time_update(0);
+ ngx_time_update();
}
}
@@ -980,7 +980,7 @@
if (ev != WAIT_TIMEOUT) {
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
"cache manager WaitForSingleObject: %ul", ev);
@@ -1008,7 +1008,7 @@
if (path[i]->loader) {
path[i]->loader(path[i]->data);
- ngx_time_update(0);
+ ngx_time_update();
}
}