From: Art Cancro Date: Fri, 23 Jul 2010 20:23:18 +0000 (+0000) Subject: * Rewrote vCtdlLogPrintf() to NOT use any buffers at all, only v*printf() type functi... X-Git-Tag: v8.01~661 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=8855aca0e6075d4745a0068e4cdf0846f1a17563 * Rewrote vCtdlLogPrintf() to NOT use any buffers at all, only v*printf() type functions. We do this by writing the log data and metadata in separate calls. In practice, this will cause them to appear on the same line even when other threads are concurrently writing because we are using buffered I/O. Unfortunately, this does NOT fix the server crash that occurs when saving instant message transcripts to disk. It points us in the right direction, though. --- diff --git a/citadel/sysdep.c b/citadel/sysdep.c index a2c74f31e..10a955a60 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -118,7 +118,7 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) struct timeval tv; struct tm tim; time_t unixtime; - CitContext *CCC = MyContext(); + CitContext *CCC = CC; ThreadTSD *cTSD = CTP; CtdlThreadNode *node = NULL; long lwpid = 0; @@ -140,30 +140,27 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) unixtime = tv.tv_sec; localtime_r(&unixtime, &tim); - *LWP = '\0'; + 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 + ); + if (lwpid != 0) { - snprintf(LWP, 64, "[LWP:%ld] ", lwpid); + fprintf(stderr, "[LWP:%ld] ", lwpid); } - *SESS = '\0'; if (CCC != NULL) { if (CCC->cs_pid != 0) { - snprintf(SESS, 64, " [%3d] ", CCC->cs_pid); + fprintf(stderr, "[%3d] ", CCC->cs_pid); } else if (CCC->user.usernum != 0) { - snprintf(SESS, 64, " [:%ld] ", CCC->user.usernum); + fprintf(stderr, "[:%ld] ", CCC->user.usernum); } } - 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); + vfprintf(stderr, format, arg_ptr); fflush(stderr); } }