summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-03-13 18:08:07 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-03-13 18:08:07 +0000
commit2f916a972139be74d437e40bdc7d236401123170 (patch)
treefcd2498751fa4da54ce7b32cfea08975893d83c9 /src/core
parentb80f68aeda3d958c6c8e52a796fcc561cd9c6e1a (diff)
downloadnginx-2f916a972139be74d437e40bdc7d236401123170.tar.gz
nginx-2f916a972139be74d437e40bdc7d236401123170.tar.bz2
*) use previously cached GMT offset value to update time from a signal handler
*) change ngx_time_update() interface since there are no notification methods those return time
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ngx_cycle.c2
-rw-r--r--src/core/ngx_times.c43
-rw-r--r--src/core/ngx_times.h2
3 files changed, 33 insertions, 14 deletions
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index d77dcc13d..2c3dcc848 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, 0);
+ ngx_time_update(0);
log = old_cycle->log;
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 3105beb47..94993e291 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -28,6 +28,17 @@ 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)
+
+/*
+ * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
+ * if ngx_time_update() is called by signal handler, it uses the cached
+ * GMT offset value. Fortunately the value is changed only two times a year.
+ */
+
+static ngx_int_t cached_gmtoff;
+#endif
+
static ngx_time_t cached_time[NGX_TIME_SLOTS];
static u_char cached_err_log_time[NGX_TIME_SLOTS]
[sizeof("1970/09/28 12:00:00")];
@@ -50,15 +61,17 @@ ngx_time_init(void)
ngx_cached_time = &cached_time[0];
- ngx_time_update(0, 0);
+ ngx_time_update(0);
}
void
-ngx_time_update(time_t sec, ngx_uint_t msec)
+ngx_time_update(ngx_uint_t use_cached_gmtoff)
{
u_char *p0, *p1, *p2;
ngx_tm_t tm, gmt;
+ time_t sec;
+ ngx_uint_t msec;
ngx_time_t *tp;
struct timeval tv;
@@ -66,12 +79,10 @@ ngx_time_update(time_t sec, ngx_uint_t msec)
return;
}
- if (sec == 0) {
- ngx_gettimeofday(&tv);
+ ngx_gettimeofday(&tv);
- sec = tv.tv_sec;
- msec = tv.tv_usec / 1000;
- }
+ sec = tv.tv_sec;
+ msec = tv.tv_usec / 1000;
ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
@@ -109,15 +120,23 @@ ngx_time_update(time_t sec, ngx_uint_t msec)
tp->gmtoff = ngx_gettimezone();
ngx_gmtime(sec + tp->gmtoff * 60, &tm);
-#elif (NGX_HAVE_GMTOFF)
+#else
+
+ if (use_cached_gmtoff) {
+ ngx_gmtime(sec + cached_gmtoff * 60, &tm);
- ngx_localtime(sec, &tm);
- tp->gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
+ } 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);
- tp->gmtoff = ngx_timezone(tm.ngx_tm_isdst);
+ tp->gmtoff = cached_gmtoff;
#endif
diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h
index 8363ca136..4259d17d1 100644
--- a/src/core/ngx_times.h
+++ b/src/core/ngx_times.h
@@ -20,7 +20,7 @@ typedef struct {
void ngx_time_init(void);
-void ngx_time_update(time_t sec, ngx_uint_t msec);
+void ngx_time_update(ngx_uint_t use_cached_gmtoff);
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);