[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r3694 - trunk/OpenDNSSEC/signer/src/util

Jakob Schlyter jakob at kirei.se
Tue Aug 10 10:56:59 CEST 2010


Author: jakob
Date: 2010-08-10 10:56:59 +0200 (Tue, 10 Aug 2010)
New Revision: 3694

Modified:
   trunk/OpenDNSSEC/signer/src/util/log.c
Log:
use ctime_r

Modified: trunk/OpenDNSSEC/signer/src/util/log.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/util/log.c	2010-08-10 08:52:43 UTC (rev 3693)
+++ trunk/OpenDNSSEC/signer/src/util/log.c	2010-08-10 08:56:59 UTC (rev 3694)
@@ -59,7 +59,9 @@
 static FILE* logfile = NULL;
 static int log_level = LOG_CRIT;
 
+#define CTIME_LENGTH 26
 
+
 /* TODO:
    - prepend ods_ in common library
    - log_init should have program_name variable)
@@ -193,8 +195,8 @@
 se_log_vmsg(int priority, const char* t, const char* s, va_list args)
 {
     char message[ODS_SE_MAXLINE];
+    static char nowstr[CTIME_LENGTH];
     time_t now = time_now();
-    char* strtime = NULL;
 
     vsnprintf(message, sizeof(message), s, args);
 
@@ -208,16 +210,12 @@
     if (!logfile) {
         return;
     }
-    strtime = ctime(&now);
-    if (strlen(strtime) > 1) {
-        strtime[strlen(strtime)-1] = '\0';
-        fprintf(logfile, "[%s] %s[%i] %s: %s\n", strtime,
-            PACKAGE_TARNAME, priority, t, message);
-    } else {
-        fprintf(logfile, "[%u] %s[%i] %s: %s\n", time(NULL),
-            PACKAGE_TARNAME, priority, t, message);
-    }
 
+    ctime_r(&now, nowstr);
+    nowstr[24] = '\0'; /* remove trailing linefeed */
+
+    fprintf(logfile, "[%s] %s[%i] %s: %s\n", nowstr,
+        PACKAGE_TARNAME, priority, t, message);
     fflush(logfile);
 }
 




More information about the Opendnssec-commits mailing list