Ticket #97: innfeed-ctime.patch

File innfeed-ctime.patch, 10.5 KB (added by Julien ÉLIE, 11 years ago)
  • doc/man/innfeed.conf.5

     
    190190 a positive value for ``\fBdebug-value\fP'', is used). This corresponds to
    191191 the ``\fI\-l\fP'' command-line option. A relative pathname is relative to
    192192 the ``\fBbacklog-directory\fP'' value.
     193.TP
     194.B log-time-format
     195This key requires a format string suitable for strftime(3). It is used for
     196messages sent via syslog(3) and to the \fBstatus-file\fP. Default value
     197is "%a %b %d %H:%M:%S %Y".
    193198 .\" .TP
    194199 .\" .B initial-sleep
    195200 .\" This key requires a positive integer value. It specifies how many seconds
  • innfeed/connection.c

     
    44614461       free (PointersFreedOnExit) ;
    44624462       freeTimeoutQueue () ;
    44634463
    4464       strlcpy (dateString,ctime (&now), sizeof(dateString)) ;
     4464      timeToString (now, dateString, sizeof(dateString)) ;
     4465      notice ("ME finishing at %s\n", dateString) ;
    44654466
    4466       notice ("ME finishing at %s", dateString) ;
    4467 
    44684467       exit (0) ;
    44694468     }
    44704469 }
  • innfeed/misc.h

     
    4242 /* debugging information */
    4343 extern unsigned int loggingLevel ;     /* if 0 then d_printf is a no-op */
    4444
     45/* used by timeToString with strftime(3) */
     46extern char *timeToStringFormat ;
     47
    4548 /* the current count of file desccriptors */
    4649 extern unsigned int openfds ;
    4750
     
    114117 /* converts val into a printable string */
    115118 const char *boolToString (bool val) ;
    116119
     120/* strftime with "%a %b %d %H:%M:%S %Y" (like ctime without linefeed) */
     121char* timeToString (time_t time, char* buffer, size_t size) ;
     122
    117123 /* memory leak checker helper. */
    118124 void addPointerFreedOnExit (char *pointerToFree) ;
    119125
  • innfeed/imap_connection.c

     
    41704170       time_t now = theTime () ;
    41714171       char dateString [30] ;
    41724172
    4173       strlcpy (dateString,ctime (&now),sizeof (dateString)) ;
    4174       dateString [24] = '\0' ;
    4175 
     4173      timeToString (now, dateString, sizeof (dateString)) ;
    41764174       notice ("ME finishing at %s", dateString) ;
    41774175
    41784176       exit (0) ;
  • innfeed/host.c

     
    332332
    333333 static unsigned int hostHighwater = HOST_HIGHWATER ;
    334334 static time_t start ;
    335 static char startTime [30] ;    /* for ctime(3) */
     335static char startTime [30] ;    /* for timeToString */
    336336 static pid_t myPid ;
    337337
    338338 static char *statusFile = NULL ;
     
    396396   else
    397397     iv = DNS_EXPIRE_PERIOD ;
    398398   dnsExpPeriod = (unsigned int) iv ;
    399 
     399
    400400   if (getBool (topScope,"gen-html",&bval,NO_INHERIT))
    401401     genHtml = (bval ? true : false) ;
    402402   else
     
    410410   else
    411411     hostSetStatusFile (INNFEED_STATUS) ;
    412412
    413 
    414413   if (getBool (topScope,"connection-stats",&bval,NO_INHERIT))
    415414     logConnectionStats = (bval ? true : false) ;
    416415   else
    417416     logConnectionStats = (LOG_CONNECTION_STATS ? true : false) ;
    418417
    419 
    420418   if (getInteger (topScope,"host-queue-highwater", &iv,NO_INHERIT))
    421419     {
    422420       if (iv < 0)
     
    11111109   if (maxIpNameLen == 0)
    11121110     {
    11131111       start = theTime() ;
    1114       strlcpy (startTime,ctime (&start),sizeof (startTime)) ;
     1112      timeToString (start, startTime, sizeof (startTime)) ;
    11151113       myPid = getpid() ;
    11161114     }
    11171115
     
    12581256
    12591257 void printHostInfo (Host host, FILE *fp, unsigned int indentAmt)
    12601258 {
     1259  char dateString [30] ;
    12611260   char indent [INDENT_BUFFER_SIZE] ;
    12621261   unsigned int i ;
    12631262   ProcQElem qe ;
     
    14041403            100.0 * host->blFull / cnt) ;
    14051404   fprintf (fp,"%s      number of samples : %u\n", indent, host->blCount) ;
    14061405
    1407   fprintf (fp,"%s    firstConnectTime : %s",indent,
    1408            ctime (&host->firstConnectTime));
    1409   fprintf (fp,"%s    connectTime : %s",indent,ctime (&host->connectTime));
    1410   fprintf (fp,"%s    spoolTime : %s",indent,ctime (&host->spoolTime)) ;
    1411   fprintf (fp,"%s    last-spool-time : %s",indent,
    1412            ctime (&host->lastSpoolTime)) ;
     1406  timeToString (host->firstConnectTime, dateString, sizeof (dateString));
     1407  fprintf (fp, "%s    firstConnectTime : %s\n", indent, dateString);
     1408
     1409  timeToString (host->connectTime, dateString, sizeof (dateString));
     1410  fprintf (fp, "%s    connectTime : %s\n", indent, dateString);
     1411
     1412  timeToString (host->spoolTime, dateString, sizeof (dateString));
     1413  fprintf (fp, "%s    spoolTime : %s\n", indent, dateString);
     1414
     1415  timeToString (host->lastSpoolTime, dateString, sizeof (dateString));
     1416  fprintf (fp, "%s    last-spool-time : %s\n", indent, dateString);
    14131417
    14141418 #if 0
    14151419   fprintf (fp,"%s    tape {\n",indent) ;
     
    31603164
    31613165       now = time (NULL) ;
    31623166       sec = (long) (now - start) ;
    3163       strlcpy (timeString,ctime (&now),sizeof (timeString)) ;
     3167      timeToString (now, timeString, sizeof (timeString)) ;
    31643168
    31653169       if (genHtml)
    31663170         {
     
    31733177   fprintf (fp, "<PRE>\n");
    31743178 }
    31753179
    3176       fprintf (fp,"innfeed from %s\npid %d started %s\nUpdated: %s",
     3180      fprintf (fp,"innfeed from %s\npid %d started %s\n\nUpdated: %s\n",
    31773181                INN_VERSION_STRING,(int) myPid,startTime,timeString) ;
    31783182       fprintf (fp,"(peers: %d active-cxns: %d sleeping-cxns: %d idle-cxns: %d)\n\n",
    31793183                peerNum, actConn, slpConn,(maxcon - (actConn + slpConn))) ;
  • innfeed/endpoint.c

     
    14951495 static void printDate (TimeoutId tid, void *data) ;
    14961496 static void printDate (TimeoutId tid, void *data)
    14971497 {
    1498   time_t t ;
     1498  char dateString[30];
     1499  const time_t t = theTime() ;
    14991500
    1500   t = theTime() ;
    1501 
    1502   d_printf (1,"Timeout (%d) time now is %ld %s",
    1503            (int) tid,(long) t,ctime(&t)) ;
     1501  timeToString (t, dateString, sizeof (dateString)) ;
     1502  d_printf (1,"Timeout (%d) time now is %ld %s\n",
     1503           (int) tid, (long) t, dateString) ;
    15041504
    15051505   if (timeoutQueue == NULL)
    15061506     {
     
    15181518   static int seeded ;
    15191519   static int howMany ;
    15201520   static int i ;
    1521   time_t t = theTime() ;
     1521  char dateString[30];
     1522  const time_t t = theTime() ;
    15221523
    15231524   if ( !seeded )
    15241525     {
     
    15261527       seeded = 1 ;
    15271528     }
    15281529
    1529   d_printf (1,"Timeout (%d) time now is %ld %s",
    1530            (int) tid, (long) t,ctime(&t)) ;
     1530  timeToString (t, dateString, sizeof (dateString)) ;
     1531  d_printf (1,"Timeout (%d) time now is %ld %s\n",
     1532           (int) tid, (long) t, dateString) ;
    15311533
    15321534   if (timeoutQueue != NULL && timeoutQueue->next != NULL)
    15331535     d_printf (1,"%s timeout id %d\n",
  • innfeed/main.c

     
    120120   bool checkConfig = false ;
    121121   bool val;
    122122
    123   strlcpy (dateString,ctime(&now),sizeof (dateString)) ;
     123  timeToString (now, dateString, sizeof (dateString)) ;
    124124
    125125   message_program_name = strrchr (argv [0],'/');
    126126   if (message_program_name == NULL)
     
    289289
    290290   if ( !checkConfig )
    291291     {
    292       notice ("ME starting at %s (%s)", dateString, INN_VERSION_STRING);
     292      notice ("ME starting at %s\n (%s)", dateString, INN_VERSION_STRING);
    293293     }
    294294
    295295   val = true;
     
    671671 {
    672672   char *snapshotFile;
    673673   FILE *fp;
     674  char nowString[30];
    674675   time_t now = theTime() ;
    675676
    676677   snapshotFile = concatpath(innconf->pathlog, SNAPSHOT_FILE);
     
    689690   setbuf (fp, NULL) ;
    690691 #endif
    691692
    692   fprintf (fp,"----------------------------System snaphot taken at: %s\n",
    693            ctime (&now)) ;
     693  timeToString (now, nowString, sizeof (nowString)) ;
     694  fprintf (fp,"----------------------------System snaphot taken at: %s\n\n",
     695           nowString) ;
    694696   gPrintListenerInfo (fp,0) ;
    695697   fprintf (fp,"\n\n\n\n") ;
    696698   gPrintHostInfo (fp,0) ;
     
    770772       free (p) ;
    771773     }
    772774
     775  if (getString (topScope,"log-time-format",&p,NO_INHERIT))
     776    {
     777      free(timeToStringFormat);
     778      timeToStringFormat = p;
     779    }
     780
    773781    /* For imap/lmtp delivering */
    774782   if (getString (topScope,"deliver-username",&p, NO_INHERIT))
    775783     {
  • innfeed/innlistener.c

     
    230230       char dateString [30] ;
    231231
    232232       gHostStats();
    233       strlcpy (dateString,ctime (&now),sizeof (dateString)) ;
    234       dateString [24] = '\0' ;
     233      timeToString (now, dateString, sizeof (dateString)) ;
    235234
    236235       if (fastExit)
    237236         notice ("ME finishing (quickly) at %s", dateString) ;
  • innfeed/misc.c

     
    4040 unsigned int loggingLevel ;
    4141 char **PointersFreedOnExit ;
    4242
     43char *timeToStringFormat = 0;
    4344 bool debuggingDump = true ;
    4445 extern void (*gPrintInfo) (void) ;
    4546 void (*gCleanUp) (void) = 0 ;
     
    115116   static pid_t myPid ;
    116117   char timeString [30] ;
    117118   time_t now ;
     119  struct tm *tm ;
    118120   va_list ap ;
    119121
    120122   if (myPid == 0)
     
    124126     return ;
    125127
    126128   now = theTime() ;
    127   /* strip off leading day name */
    128   strlcpy (timeString, ctime (&now) + 4, sizeof (timeString)) ;
    129   timeString [15] = '\0' ;      /* strip off trailing year and newline */
     129  tm = localtime (&now);
     130  strftime (timeString, sizeof(timeString), "%b %d %H:%M:%S", tm);
    130131
    131132   va_start (ap, fmt) ;
    132133   fprintf (stderr, "%s %s[%ld]: ",timeString,
     
    591592   return val ? "true" : "false" ;
    592593 }
    593594
     595char* timeToString(time_t t, char* buffer, size_t size)
     596{
     597  static const char defaultFormat[] = "%a %b %d %H:%M:%S %Y" ;
     598  const struct tm *const tm = localtime(&t);
     599  strftime (buffer, size,
     600    timeToStringFormat == 0 ? defaultFormat : timeToStringFormat, tm);
     601  return buffer;
     602}
     603
    594604 void addPointerFreedOnExit (char *pointerToFree)
    595605 {
    596606   static int totalPointers = 0 ;