]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
OpenBSD: introduce SCLocalTime function.
authorEric Leblond <eric@regit.org>
Sun, 20 May 2012 15:12:19 +0000 (17:12 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 25 May 2012 14:00:22 +0000 (16:00 +0200)
This function is a wrapper to localtime_r. It is needed to avoid
a compilation warning on OpenBSD. I'm forced to type the function
to a non pointer first parameter. If not we will have to use two
differents functions in OpenBSD where tv->tv_sec is a long
(different from time_t).

13 files changed:
src/alert-debuglog.c
src/alert-fastlog.c
src/counters.c
src/detect.c
src/log-droplog.c
src/log-file.c
src/log-filestore.c
src/log-httplog.c
src/log-pcap.c
src/util-debug.c
src/util-profiling.c
src/util-time.c
src/util-time.h

index b61a3440605907b44de1976661d3f980c2b1687e..1029e621f2388ea33d944dc18f1e53258954ebbf 100644 (file)
@@ -89,7 +89,7 @@ typedef struct AlertDebugLogThread_ {
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm*)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
         t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index a7060447ee76450a89b6546c4a55b12456b7943f..3ed3042a33295a471d623e4ddf5f87b30fc2c762 100644 (file)
@@ -110,7 +110,7 @@ typedef struct AlertFastLogThread_ {
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
             t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index bbb76a0d9d0261b6d4ea7ff6ba34de547e14782e..cf4f9f3e9ecf464e9fc0608445e96a6204806241 100644 (file)
@@ -1022,7 +1022,7 @@ static int SCPerfOutputCounterFileIface()
 
     gettimeofday(&tval, NULL);
     struct tm local_tm;
-    tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
+    tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
 
     /* Calculate the Engine uptime */
     int up_time = (int)difftime(tval.tv_sec, sc_start_time);
index ad60a254f1a02f081301b59aeb8577587a715c9a..4a634fc7fd693160801a91f01ee0a69ea6adef14 100644 (file)
@@ -587,7 +587,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
             struct tm *tms;
             gettimeofday(&tval, NULL);
             struct tm local_tm;
-            tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
+            tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
             fprintf(fp_engine_analysis_FD, "----------------------------------------------"
                     "---------------------\n");
             fprintf(fp_engine_analysis_FD, "Date: %" PRId32 "/%" PRId32 "/%04d -- "
index 6404a751f99596704b47cfcc3e5aef2d01165589..caac9640de06a8cb4d77f95998c0bc3479499108 100644 (file)
@@ -188,7 +188,7 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx)
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
             t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index 224d21a44356b69e86029e36eb42f7390f186562..3bbd5276b6902018dde0411f13adfaa2155b4bc3 100644 (file)
@@ -93,7 +93,7 @@ typedef struct LogFileLogThread_ {
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
         t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index 750bbdd4ca2be82aeb6f84bb2776e9855def6e71..0991f566dfd2c2333fbc3204c99f0a0552f3e09d 100644 (file)
@@ -96,7 +96,7 @@ typedef struct LogFilestoreLogThread_ {
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
         t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index 3e1118706b435f879731027beae1ec40471591f0..aeeea50fc1cdde8b6dd77f4f9a4368c36cc9cd56 100644 (file)
@@ -115,7 +115,7 @@ typedef struct LogHttpLogThread_ {
 static void CreateTimeString (const struct timeval *ts, char *str, size_t size) {
     time_t time = ts->tv_sec;
     struct tm local_tm;
-    struct tm *t = (struct tm *)localtime_r(&time, &local_tm);
+    struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
 
     snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
         t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
index 05f31df227b02c522d0fad2185a7025e52692bdf..4db305adddf18e08ee340a30e33d0d350fe56302 100644 (file)
@@ -280,7 +280,7 @@ TmEcode PcapLog (ThreadVars *t, Packet *p, void *data, PacketQueue *pq,
 
     if (pl->mode == LOGMODE_SGUIL) {
         struct tm local_tm;
-        struct tm *tms = (struct tm *)localtime_r(&p->ts.tv_sec, &local_tm);
+        struct tm *tms = (struct tm *)SCLocalTime(p->ts.tv_sec, &local_tm);
         if (tms->tm_mday != pl->prev_day) {
             rotate = 1;
             pl->prev_day = tms->tm_mday;
@@ -350,7 +350,7 @@ TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data)
     memset(&ts, 0x00, sizeof(struct timeval));
     TimeGet(&ts);
     struct tm local_tm;
-    struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm);
+    struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm);
     pl->prev_day = tms->tm_mday;
 
     *data = (void *)pl;
@@ -623,7 +623,7 @@ int PcapLogOpenFileCtx(PcapLogData *pl)
 
     if (pl->mode == LOGMODE_SGUIL) {
         struct tm local_tm;
-        struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm);
+        struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm);
 
         char dirname[32], dirfull[PATH_MAX] = "";
 
index 620ade1f2546b9649dedd1507e59435c7a948bda..b3a7342cec40147879ffbc19880ff04196121b7b 100644 (file)
@@ -320,7 +320,7 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
 
                 gettimeofday(&tval, NULL);
                 struct tm local_tm;
-                tms = localtime_r(&tval.tv_sec, &local_tm);
+                tms = SCLocalTime(tval.tv_sec, &local_tm);
 
                 cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
                               "%s%d/%d/%04d -- %02d:%02d:%02d",
index 00e2f80a9bb15d31ea87dbe00b00851a80334831..3365526fd696e6fbecfe05ef2265235f1f326eae 100644 (file)
@@ -569,7 +569,7 @@ SCProfilingDump(void)
 
     gettimeofday(&tval, NULL);
     struct tm local_tm;
-    tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm);
+    tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm);
 
     fprintf(fp, "  ----------------------------------------------"
             "----------------------------\n");
index 5d7eb489eb852708f779398bd288a7297dc2db94..a7a3b4c178a3828287bbe1298c62cb94fe4e1297 100644 (file)
@@ -111,3 +111,8 @@ void TimeSetIncrementTime(uint32_t tv_sec) {
     TimeSet(&tv);
 }
 
+
+struct tm *SCLocalTime(time_t timep, struct tm *result)
+{
+    return localtime_r(&timep, result);
+}
index a413407c6b2d76578b9ed06e2ce1ad0138c3bb98..fc18db8d5110174f3e3c6f65973bc15b339ff302 100644 (file)
@@ -46,5 +46,7 @@ void TimeSetIncrementTime(uint32_t);
 void TimeModeSetLive(void);
 void TimeModeSetOffline (void);
 
+struct tm *SCLocalTime(time_t timep, struct tm *result);
+
 #endif /* __UTIL_TIME_H__ */