@@ -514,11 +514,13 @@ void putlog (int type, char *chname, const char *format, ...)
514514{
515515 static int inhere = 0 ;
516516 int i , tsl = 0 ;
517- char s [LOGLINELEN ], path [PATH_MAX ], * out , ct [81 ], * s2 , stamp [34 ];
517+ char s [LOGLINELEN ], path [PATH_MAX ], * out , ct [81 ], * s2 , stamp [34 ],
518+ stamp2 [sizeof stamp ], * f , c ;
518519 va_list va ;
519520 time_t now2 = time (NULL );
520521 static time_t now2_last = 0 ; /* cache expensive localtime() */
521522 static struct tm t ;
523+ struct timeval tv ;
522524
523525 if (now2 != now2_last ) {
524526 now2_last = now2 ;
@@ -529,12 +531,25 @@ void putlog (int type, char *chname, const char *format, ...)
529531
530532 /* Create the timestamp */
531533 if (shtime ) {
532- strftime (stamp , sizeof (stamp ) - 2 , log_ts , & t );
533- strcat (stamp , " " );
534- tsl = strlen (stamp );
534+ strlcpy (stamp , log_ts , sizeof stamp );
535+
536+ /* handle millisecond specifier %f */
537+ if ((f = strstr (stamp , "%f" )) && ((f - 1 ) != (strstr (stamp , "%%f" )))) {
538+ memmove (f + 3 , f + 2 , strlen (f + 2 ) + 1 );
539+ c = f [3 ]; /* save the char the following snprintf() will overwrite with
540+ * null terminator
541+ */
542+ gettimeofday (& tv , NULL );
543+ snprintf (f , sizeof stamp - (f - stamp ), "%03i" , (int ) tv .tv_usec / 1000 );
544+ f [3 ] = c ;
545+ }
546+
547+ strftime (stamp2 , sizeof (stamp2 ) - 2 , stamp , & t );
548+ strcat (stamp2 , " " );
549+ tsl = strlen (stamp2 );
535550 }
536551 else
537- * stamp = '\0' ;
552+ * stamp2 = '\0' ;
538553
539554 /* Format log entry at offset 'tsl,' then i can prepend the timestamp */
540555 out = s + tsl ;
@@ -566,7 +581,7 @@ void putlog (int type, char *chname, const char *format, ...)
566581 }
567582 /* Place the timestamp in the string to be printed */
568583 if (out [0 ] && shtime ) {
569- memcpy (s , stamp , tsl );
584+ memcpy (s , stamp2 , tsl );
570585 out = s ;
571586 }
572587 strcat (out , "\n" );
@@ -599,7 +614,7 @@ void putlog (int type, char *chname, const char *format, ...)
599614 * then reset repeats. We want the current time here,
600615 * so put that in the file first.
601616 */
602- fprintf (logs [i ].f , "%s" , stamp );
617+ fprintf (logs [i ].f , "%s" , stamp2 );
603618 fprintf (logs [i ].f , MISC_LOGREPEAT , logs [i ].repeats );
604619 logs [i ].repeats = 0 ;
605620 /* No need to reset logs[i].szlast here
0 commit comments