From 2b04732314572d8a432b706f3d3d5c34d67f16a4 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 13 Oct 2010 21:51:27 +0200 Subject: [PATCH] * vCtdlLogPrintf(): combine the server data plus the application format string into a new format string we then process with va_args. -> still no strbuf needed -> no problems with race conditions causing clashes between several lines --- citadel/sysdep.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 09b66f286..a2c74f31e 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -122,6 +122,9 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) ThreadTSD *cTSD = CTP; CtdlThreadNode *node = NULL; long lwpid = 0; + char formatbuf[SIZ]; + char LWP[64]; + char SESS[64]; if (cTSD != NULL) { node = cTSD->self; @@ -137,27 +140,30 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) unixtime = tv.tv_sec; localtime_r(&unixtime, &tim); - fprintf(stderr, - "%04d/%02d/%02d %2d:%02d:%02d.%06ld ", - tim.tm_year + 1900, tim.tm_mon + 1, - tim.tm_mday, tim.tm_hour, tim.tm_min, - tim.tm_sec, (long)tv.tv_usec - ); - + *LWP = '\0'; if (lwpid != 0) { - fprintf(stderr, "[LWP:%ld] ", lwpid); + snprintf(LWP, 64, "[LWP:%ld] ", lwpid); } + *SESS = '\0'; if (CCC != NULL) { if (CCC->cs_pid != 0) { - fprintf(stderr, "[%3d] ", CCC->cs_pid); + snprintf(SESS, 64, " [%3d] ", CCC->cs_pid); } else if (CCC->user.usernum != 0) { - fprintf(stderr, "[:%ld] ", CCC->user.usernum); + snprintf(SESS, 64, " [:%ld] ", CCC->user.usernum); } } - vfprintf(stderr, format, arg_ptr); + snprintf(formatbuf, SIZ, + "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s%s%s", + tim.tm_year + 1900, tim.tm_mon + 1, + tim.tm_mday, tim.tm_hour, tim.tm_min, + tim.tm_sec, (long)tv.tv_usec, + LWP, SESS, format + ); + + vfprintf(stderr, formatbuf, arg_ptr); fflush(stderr); } } -- 2.30.2