INN commit: trunk (10 files)

INN Commit Russ_Allbery at isc.org
Sun Dec 21 11:50:47 UTC 2008


    Date: Sunday, December 21, 2008 @ 03:50:47
  Author: iulius
Revision: 8243

Add a new log-time-format: parameter for innfeed.
Change ctime(3) to strftime(3).
Update documentation and innfeed.conf sample file.

Thanks to Alexander Bartolich for the patch.

close #97

Modified:
  trunk/doc/man/innfeed.conf.5
  trunk/innfeed/connection.c
  trunk/innfeed/endpoint.c
  trunk/innfeed/host.c
  trunk/innfeed/imap_connection.c
  trunk/innfeed/innlistener.c
  trunk/innfeed/main.c
  trunk/innfeed/misc.c
  trunk/innfeed/misc.h
  trunk/samples/innfeed.conf

---------------------------+
 doc/man/innfeed.conf.5    |    5 +++++
 innfeed/connection.c      |    5 ++---
 innfeed/endpoint.c        |   20 +++++++++++---------
 innfeed/host.c            |   30 +++++++++++++++++-------------
 innfeed/imap_connection.c |    4 +---
 innfeed/innlistener.c     |    3 +--
 innfeed/main.c            |   16 ++++++++++++----
 innfeed/misc.c            |   16 +++++++++++++---
 innfeed/misc.h            |    6 ++++++
 samples/innfeed.conf      |    1 +
 10 files changed, 69 insertions(+), 37 deletions(-)

Modified: doc/man/innfeed.conf.5
===================================================================
--- doc/man/innfeed.conf.5	2008-12-21 10:29:55 UTC (rev 8242)
+++ doc/man/innfeed.conf.5	2008-12-21 11:50:47 UTC (rev 8243)
@@ -190,6 +190,11 @@
 a positive value for ``\fBdebug-value\fP'', is used). This corresponds to 
 the ``\fI\-l\fP'' command-line option. A relative pathname is relative to
 the ``\fBbacklog-directory\fP'' value.
+.TP
+.B log-time-format
+This key requires a format string suitable for strftime(3). It is used for
+messages sent via syslog(3) and to the \fBstatus-file\fP. Default value
+is "%a %b %d %H:%M:%S %Y".
 .\" .TP
 .\" .B initial-sleep
 .\" This key requires a positive integer value. It specifies how many seconds

Modified: innfeed/connection.c
===================================================================
--- innfeed/connection.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/connection.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -4461,10 +4461,9 @@
       free (PointersFreedOnExit) ;
       freeTimeoutQueue () ;
 
-      strlcpy (dateString,ctime (&now), sizeof(dateString)) ;
+      timeToString (now, dateString, sizeof(dateString)) ;
+      notice ("ME finishing at %s\n", dateString) ;
 
-      notice ("ME finishing at %s", dateString) ;
-
       exit (0) ;
     }
 }

Modified: innfeed/endpoint.c
===================================================================
--- innfeed/endpoint.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/endpoint.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -1495,12 +1495,12 @@
 static void printDate (TimeoutId tid, void *data) ;
 static void printDate (TimeoutId tid, void *data)
 {
-  time_t t ;
+  char dateString[30];
+  const time_t t = theTime() ;
 
-  t = theTime() ;
-  
-  d_printf (1,"Timeout (%d) time now is %ld %s",
-           (int) tid,(long) t,ctime(&t)) ;
+  timeToString (t, dateString, sizeof (dateString)) ;
+  d_printf (1,"Timeout (%d) time now is %ld %s\n",
+            (int) tid, (long) t, dateString) ;
 
   if (timeoutQueue == NULL) 
     {
@@ -1518,7 +1518,8 @@
   static int seeded ;
   static int howMany ;
   static int i ;
-  time_t t = theTime() ;
+  char dateString[30];
+  const time_t t = theTime() ;
 
   if ( !seeded )
     {
@@ -1526,9 +1527,10 @@
       seeded = 1 ;
     }
 
-  d_printf (1,"Timeout (%d) time now is %ld %s",
-           (int) tid, (long) t,ctime(&t)) ;
-  
+  timeToString (t, dateString, sizeof (dateString)) ;
+  d_printf (1,"Timeout (%d) time now is %ld %s\n",
+            (int) tid, (long) t, dateString) ;
+
   if (timeoutQueue != NULL && timeoutQueue->next != NULL)
     d_printf (1,"%s timeout id %d\n",
              (removeTimeout (rm) ? "REMOVED" : "FAILED TO REMOVE"), rm) ;

Modified: innfeed/host.c
===================================================================
--- innfeed/host.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/host.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -332,7 +332,7 @@
 
 static unsigned int hostHighwater = HOST_HIGHWATER ;
 static time_t start ;
-static char startTime [30] ;    /* for ctime(3) */
+static char startTime [30] ;    /* for timeToString */
 static pid_t myPid ;
 
 static char *statusFile = NULL ;
@@ -410,13 +410,11 @@
   else
     hostSetStatusFile (INNFEED_STATUS) ;
   
-  
   if (getBool (topScope,"connection-stats",&bval,NO_INHERIT))
     logConnectionStats = (bval ? true : false) ;
   else
     logConnectionStats = (LOG_CONNECTION_STATS ? true : false) ;
 
-
   if (getInteger (topScope,"host-queue-highwater", &iv,NO_INHERIT))
     {
       if (iv < 0)
@@ -1111,7 +1109,7 @@
   if (maxIpNameLen == 0)
     {
       start = theTime() ;
-      strlcpy (startTime,ctime (&start),sizeof (startTime)) ;
+      timeToString (start, startTime, sizeof (startTime)) ;
       myPid = getpid() ;
     }
   
@@ -1258,6 +1256,7 @@
 
 void printHostInfo (Host host, FILE *fp, unsigned int indentAmt)
 {
+  char dateString [30] ;
   char indent [INDENT_BUFFER_SIZE] ;
   unsigned int i ;
   ProcQElem qe ;
@@ -1404,13 +1403,18 @@
            100.0 * host->blFull / cnt) ;
   fprintf (fp,"%s      number of samples : %u\n", indent, host->blCount) ;
 
-  fprintf (fp,"%s    firstConnectTime : %s",indent,
-           ctime (&host->firstConnectTime));
-  fprintf (fp,"%s    connectTime : %s",indent,ctime (&host->connectTime));
-  fprintf (fp,"%s    spoolTime : %s",indent,ctime (&host->spoolTime)) ;
-  fprintf (fp,"%s    last-spool-time : %s",indent,
-           ctime (&host->lastSpoolTime)) ;
-  
+  timeToString (host->firstConnectTime, dateString, sizeof (dateString));
+  fprintf (fp, "%s    firstConnectTime : %s\n", indent, dateString);
+
+  timeToString (host->connectTime, dateString, sizeof (dateString));
+  fprintf (fp, "%s    connectTime : %s\n", indent, dateString);
+
+  timeToString (host->spoolTime, dateString, sizeof (dateString));
+  fprintf (fp, "%s    spoolTime : %s\n", indent, dateString);
+
+  timeToString (host->lastSpoolTime, dateString, sizeof (dateString));
+  fprintf (fp, "%s    last-spool-time : %s\n", indent, dateString);
+
 #if 0
   fprintf (fp,"%s    tape {\n",indent) ;
   printTapeInfo (host->myTape,fp,indentAmt + INDENT_INCR) ;
@@ -3160,7 +3164,7 @@
       
       now = time (NULL) ;
       sec = (long) (now - start) ;
-      strlcpy (timeString,ctime (&now),sizeof (timeString)) ;
+      timeToString (now, timeString, sizeof (timeString)) ;
 
       if (genHtml)
         {
@@ -3173,7 +3177,7 @@
 	  fprintf (fp, "<PRE>\n");
 	}
 
-      fprintf (fp,"innfeed from %s\npid %d started %s\nUpdated: %s",
+      fprintf (fp,"innfeed from %s\npid %d started %s\n\nUpdated: %s\n",
                INN_VERSION_STRING,(int) myPid,startTime,timeString) ;
       fprintf (fp,"(peers: %d active-cxns: %d sleeping-cxns: %d idle-cxns: %d)\n\n",
                peerNum, actConn, slpConn,(maxcon - (actConn + slpConn))) ;

Modified: innfeed/imap_connection.c
===================================================================
--- innfeed/imap_connection.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/imap_connection.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -4170,9 +4170,7 @@
       time_t now = theTime () ;
       char dateString [30] ;
 
-      strlcpy (dateString,ctime (&now),sizeof (dateString)) ;
-      dateString [24] = '\0' ;
-
+      timeToString (now, dateString, sizeof (dateString)) ;
       notice ("ME finishing at %s", dateString) ;
 
       exit (0) ;

Modified: innfeed/innlistener.c
===================================================================
--- innfeed/innlistener.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/innlistener.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -230,8 +230,7 @@
       char dateString [30] ;
 
       gHostStats();
-      strlcpy (dateString,ctime (&now),sizeof (dateString)) ;
-      dateString [24] = '\0' ;
+      timeToString (now, dateString, sizeof (dateString)) ;
 
       if (fastExit)
         notice ("ME finishing (quickly) at %s", dateString) ;

Modified: innfeed/main.c
===================================================================
--- innfeed/main.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/main.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -120,7 +120,7 @@
   bool checkConfig = false ;
   bool val;
 
-  strlcpy (dateString,ctime(&now),sizeof (dateString)) ;
+  timeToString (now, dateString, sizeof (dateString)) ;
 
   message_program_name = strrchr (argv [0],'/');
   if (message_program_name == NULL)
@@ -289,7 +289,7 @@
 
   if ( !checkConfig ) 
     {
-      notice ("ME starting at %s (%s)", dateString, INN_VERSION_STRING);
+      notice ("ME starting at %s\n (%s)", dateString, INN_VERSION_STRING);
     }
 
   val = true;
@@ -671,6 +671,7 @@
 {
   char *snapshotFile;
   FILE *fp;
+  char nowString[30];
   time_t now = theTime() ;
 
   snapshotFile = concatpath(innconf->pathlog, SNAPSHOT_FILE);
@@ -689,8 +690,9 @@
   setbuf (fp, NULL) ;
 #endif
 
-  fprintf (fp,"----------------------------System snaphot taken at: %s\n",
-           ctime (&now)) ;
+  timeToString (now, nowString, sizeof (nowString)) ;
+  fprintf (fp,"----------------------------System snaphot taken at: %s\n\n",
+           nowString) ;
   gPrintListenerInfo (fp,0) ;
   fprintf (fp,"\n\n\n\n") ;
   gPrintHostInfo (fp,0) ;
@@ -770,6 +772,12 @@
       free (p) ;
     }
 
+  if (getString (topScope,"log-time-format",&p,NO_INHERIT))
+    {
+      free(timeToStringFormat);
+      timeToStringFormat = p;
+    }
+
    /* For imap/lmtp delivering */
   if (getString (topScope,"deliver-username",&p, NO_INHERIT))
     {   

Modified: innfeed/misc.c
===================================================================
--- innfeed/misc.c	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/misc.c	2008-12-21 11:50:47 UTC (rev 8243)
@@ -40,6 +40,7 @@
 unsigned int loggingLevel ;
 char **PointersFreedOnExit ;
 
+char *timeToStringFormat = 0;
 bool debuggingDump = true ;
 extern void (*gPrintInfo) (void) ;
 void (*gCleanUp) (void) = 0 ;
@@ -115,6 +116,7 @@
   static pid_t myPid ;
   char timeString [30] ;
   time_t now ;
+  struct tm *tm ;
   va_list ap ;
     
   if (myPid == 0)
@@ -124,9 +126,8 @@
     return ;
   
   now = theTime() ;
-  /* strip off leading day name */
-  strlcpy (timeString, ctime (&now) + 4, sizeof (timeString)) ;
-  timeString [15] = '\0' ;      /* strip off trailing year and newline */
+  tm = localtime (&now);
+  strftime (timeString, sizeof(timeString), "%b %d %H:%M:%S", tm);
 
   va_start (ap, fmt) ;
   fprintf (stderr, "%s %s[%ld]: ",timeString,
@@ -591,6 +592,15 @@
   return val ? "true" : "false" ;
 }
 
+char* timeToString(time_t t, char* buffer, size_t size)
+{
+  static const char defaultFormat[] = "%a %b %d %H:%M:%S %Y" ;
+  const struct tm *const tm = localtime(&t);
+  strftime (buffer, size,
+    timeToStringFormat == 0 ? defaultFormat : timeToStringFormat, tm);
+  return buffer;
+}
+
 void addPointerFreedOnExit (char *pointerToFree)
 {
   static int totalPointers = 0 ;

Modified: innfeed/misc.h
===================================================================
--- innfeed/misc.h	2008-12-21 10:29:55 UTC (rev 8242)
+++ innfeed/misc.h	2008-12-21 11:50:47 UTC (rev 8243)
@@ -42,6 +42,9 @@
 /* debugging information */
 extern unsigned int loggingLevel ;     /* if 0 then d_printf is a no-op */
 
+/* used by timeToString with strftime(3) */
+extern char *timeToStringFormat ;
+
 /* the current count of file desccriptors */
 extern unsigned int openfds ;
 
@@ -114,6 +117,9 @@
 /* converts val into a printable string */
 const char *boolToString (bool val) ;
 
+/* strftime with "%a %b %d %H:%M:%S %Y" (like ctime without linefeed) */
+char* timeToString (time_t time, char* buffer, size_t size) ;
+
 /* memory leak checker helper. */
 void addPointerFreedOnExit (char *pointerToFree) ;
 

Modified: samples/innfeed.conf
===================================================================
--- samples/innfeed.conf	2008-12-21 10:29:55 UTC (rev 8242)
+++ samples/innfeed.conf	2008-12-21 11:50:47 UTC (rev 8243)
@@ -15,6 +15,7 @@
 use-mmap:			false
 log-file:			innfeed.log		# relative to pathlog
 stdio-fdmax:			0
+log-time-format:                "%a %b %d %H:%M:%S %Y"
 
 ## Uncomment the next line to include the contents
 ## of ``testfile'' at this point.




More information about the inn-committers mailing list