]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Use own localtime/gmtime
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 18 Feb 2018 13:35:59 +0000 (13:35 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 18 Feb 2018 13:35:59 +0000 (13:35 +0000)
src/controller.c
src/libserver/worker_util.c
src/libutil/http.c
src/libutil/logger.c
src/libutil/util.c
src/libutil/util.h
src/lua/lua_task.c

index 8de9cde8ed809bbac345a08b5f7d5884df2da5e3..61e00fdd58b6acef3f55af92fab3f6ec1dc535b8 100644 (file)
@@ -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);
index 2ce4aaded9aae4b81051a80d627c94833000afae..7c92dc3596b767ed5b18d9758b5889dba3184570 100644 (file)
@@ -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",
index 9e3e2f2a1135e24b760ae57d7f03f6392676d808..5732f8b8e7ab4eed2a27a352f67124909e627377 100644 (file)
@@ -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,
index 1fade8164240328d86f38761a89f7ebae446f0cc..6b83ddb0574aa2407412b1909e8c14f4ac53cc6a 100644 (file)
@@ -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];
index bf18d8fc4f9bad42107a2261216e6f00e558440f..5e271ed80d1d34468a647b072a06bc7a9b68d39c 100644 (file)
@@ -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
index 03399fec3a8ed7b8bcf570a3203576995489a2bf..6470b5c456b777b4f46850703916bafc256e86a6 100644 (file)
@@ -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))
 
index 580a847d4f696092cf239b9e8d2a1052f9733b70..bfe5079fd0520a36a90a8e79ad2ab06b1abafce0 100644 (file)
@@ -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