summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-18 13:35:59 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-18 13:35:59 +0000
commitf1becea682b563d366add102cd88431f15182b26 (patch)
treeddb0f320ccddad22add4ff5425c53c3dd70696cb
parentc1c7b9c63d6d2cdf5c42443b7a9c8c80bae49162 (diff)
downloadrspamd-f1becea682b563d366add102cd88431f15182b26.tar.gz
rspamd-f1becea682b563d366add102cd88431f15182b26.zip
[Minor] Use own localtime/gmtime
-rw-r--r--src/controller.c6
-rw-r--r--src/libserver/worker_util.c6
-rw-r--r--src/libutil/http.c7
-rw-r--r--src/libutil/logger.c6
-rw-r--r--src/libutil/util.c10
-rw-r--r--src/libutil/util.h4
-rw-r--r--src/lua/lua_task.c4
7 files changed, 23 insertions, 20 deletions
diff --git a/src/controller.c b/src/controller.c
index 8de9cde8e..61e00fdd5 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -1352,7 +1352,7 @@ rspamd_controller_handle_legacy_history (
{
struct roll_history_row *row, *copied_rows;
guint i, rows_proc, row_num;
- struct tm *tm;
+ struct tm tm;
gchar timebuf[32];
ucl_object_t *top, *obj;
@@ -1373,8 +1373,8 @@ rspamd_controller_handle_legacy_history (
row = &copied_rows[row_num];
/* Get only completed rows */
if (row->completed) {
- tm = localtime (&row->tv.tv_sec);
- strftime (timebuf, sizeof (timebuf) - 1, "%Y-%m-%d %H:%M:%S", tm);
+ rspamd_localtime (row->tv.tv_sec, &tm);
+ strftime (timebuf, sizeof (timebuf) - 1, "%Y-%m-%d %H:%M:%S", &tm);
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromstring (
timebuf), "time", 0, false);
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 2ce4aaded..7c92dc359 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -791,7 +791,7 @@ rspamd_sessions_cache_periodic (gint fd, short what, gpointer p)
gchar timebuf[32];
gpointer k, v;
struct rspamd_worker_session_elt *elt;
- struct tm *tms;
+ struct tm tms;
GPtrArray *res;
guint i;
@@ -808,8 +808,8 @@ rspamd_sessions_cache_periodic (gint fd, short what, gpointer p)
g_ptr_array_sort (res, rspamd_session_cache_sort_cmp);
PTR_ARRAY_FOREACH (res, i, elt) {
- tms = localtime (&elt->when);
- strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms);
+ rspamd_localtime (elt->when, &tms);
+ strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", &tms);
msg_warn ("redundant session; ptr: %p, "
"tag: %s, refcount: %d, time: %s",
diff --git a/src/libutil/http.c b/src/libutil/http.c
index 9e3e2f2a1..5732f8b8e 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -1745,15 +1745,14 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted,
{
gchar datebuf[64];
gint meth_len = 0;
- struct tm t, *ptm;
+ struct tm t;
if (conn->type == RSPAMD_HTTP_SERVER) {
/* Format reply */
if (msg->method < HTTP_SYMBOLS) {
rspamd_ftok_t status;
- ptm = gmtime (&msg->date);
- t = *ptm;
+ rspamd_gmtime (msg->date, &t);
rspamd_snprintf (datebuf, sizeof(datebuf),
"%s, %02d %s %4d %02d:%02d:%02d GMT", http_week[t.tm_wday],
t.tm_mday, http_month[t.tm_mon], t.tm_year + 1900,
@@ -3689,7 +3688,7 @@ rspamd_http_date_format (gchar *buf, gsize len, time_t time)
{
struct tm tms;
- tms = *gmtime (&time);
+ rspamd_gmtime (time, &tms);
return rspamd_snprintf (buf, len, "%s, %02d %s %4d %02d:%02d:%02d GMT",
http_week[tms.tm_wday], tms.tm_mday,
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 1fade8164..6b83ddb05 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -866,7 +866,7 @@ file_log_function (const gchar *module, const gchar *id,
static gchar tmpbuf[256], timebuf[64], modulebuf[64];
gchar *m;
gdouble now;
- struct tm *tms;
+ struct tm tms;
struct iovec iov[5];
gulong r = 0, mr = 0;
guint64 cksum;
@@ -1011,8 +1011,8 @@ file_log_function (const gchar *module, const gchar *id,
time_t sec = now;
gsize r;
- tms = localtime (&sec);
- r = strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms);
+ rspamd_localtime (sec, &tms);
+ r = strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", &tms);
if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) {
gchar usec_buf[16];
diff --git a/src/libutil/util.c b/src/libutil/util.c
index bf18d8fc4..5e271ed80 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2669,7 +2669,7 @@ rspamd_tm_to_time (const struct tm *tm, glong tz)
void
-rspamd_gmtime (guint64 ts, struct tm *dest)
+rspamd_gmtime (gint64 ts, struct tm *dest)
{
guint64 days, secs, years;
int remdays, remsecs, remyears;
@@ -2756,7 +2756,9 @@ rspamd_gmtime (guint64 ts, struct tm *dest)
dest->tm_hour = remsecs / 3600;
dest->tm_min = remsecs / 60 % 60;
dest->tm_sec = remsecs % 60;
+#if !defined(__sun)
dest->tm_gmtoff = 0;
+#endif
dest->tm_zone = "GMT";
}
@@ -2764,9 +2766,9 @@ extern char *tzname[2];
extern long timezone;
extern int daylight;
-void rspamd_localtime (guint64 ts, struct tm *dest)
+void rspamd_localtime (gint64 ts, struct tm *dest)
{
- static guint64 last_tzcheck = 0;
+ static gint64 last_tzcheck = 0;
static const guint tz_check_interval = 120;
if (ts - last_tzcheck > tz_check_interval) {
@@ -2777,7 +2779,9 @@ void rspamd_localtime (guint64 ts, struct tm *dest)
ts += timezone;
rspamd_gmtime (ts, dest);
dest->tm_zone = daylight ? (tzname[1] ? tzname[1] : tzname[0]) : tzname[0];
+#if !defined(__sun)
dest->tm_gmtoff = timezone;
+#endif
}
gboolean
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 03399fec3..6470b5c45 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -479,14 +479,14 @@ guint64 rspamd_tm_to_time (const struct tm *tm, glong tz);
* @param ts
* @param dest
*/
-void rspamd_gmtime (guint64 ts, struct tm *dest);
+void rspamd_gmtime (gint64 ts, struct tm *dest);
/**
* Split unix timestamp into struct tm using local timezone
* @param ts
* @param dest
*/
-void rspamd_localtime (guint64 ts, struct tm *dest);
+void rspamd_localtime (gint64 ts, struct tm *dest);
#define PTR_ARRAY_FOREACH(ar, i, cur) for ((i) = 0; (ar) != NULL && (i) < (ar)->len && (((cur) = g_ptr_array_index((ar), (i))) || 1); ++(i))
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 580a847d4..bfe5079fd 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -3383,7 +3383,7 @@ lua_task_get_date (lua_State *L)
time_t tt;
tt = tim;
- localtime_r (&tt, &t);
+ rspamd_localtime (tt, &t);
#if !defined(__sun)
t.tm_gmtoff = 0;
#endif
@@ -3404,7 +3404,7 @@ lua_task_get_date (lua_State *L)
tt = rspamd_parse_smtp_date (h->decoded, strlen (h->decoded));
if (!gmt) {
- localtime_r (&tt, &t);
+ rspamd_localtime (tt, &t);
#if !defined(__sun)
t.tm_gmtoff = 0;
#endif