Hi. I run clamav from smtp daemon. All output of daemon itself and all child processes is logged to a file. Thus, messages from several processes are mixed together. This is not a problem as long as each process emits each message line in one go (in other words, in single write syscall).
clamav does not do this, and logging sometimes breaks: LibClamAV Warning: ******************************************************** LibClamAV Warning: *** This version of the ClamAV engine is outdated. *** LibClamAV Warning: *** DON'T PANIC! Read http://www.clamav.net/faq.html *** LibClamAV Warning: smtpfront-qmail[17611]: bytes in: 0 bytes out: 23 tcpserver: end 17611 status 0 tcpserver: status: 24/25 tcpserver: status: 25/25 tcpserver: pid 17670 from 203.101.178.30 tcpserver: ok 17670 0:195.66.192.170:25 :203.101.178.30::1366 ******************************************************** smtpfront-qmail[17635]: bytes in: 0 bytes out: 23 This happens because "LibClamAV Warning: " and "****************" are fprintf'ed as two separate strings to stderr, and stderr is unbuffered. This is important to fix for me because I post-process logs (I build SQL statements for a database of past mail). Patch is attached, please apply. -- vda
diff -urpN clamav-0.85.1.0.orig/libclamav/others.c clamav-0.85.1.z.cur/libclamav/others.c --- clamav-0.85.1.0.orig/libclamav/others.c Wed May 11 05:50:35 2005 +++ clamav-0.85.1.z.cur/libclamav/others.c Tue May 24 10:20:35 2005 @@ -80,23 +80,33 @@ short cli_debug_flag = 0, cli_leavetemps static unsigned char oldmd5buff[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, 33, 124, 18, 11, 17, 253 }; +static char cli_buf[256]; + void cli_warnmsg(const char *str, ...) { va_list args; + int sz = sizeof("LibClamAV Warning: ")-1; + + memcpy(cli_buf, "LibClamAV Warning: ", sz); va_start(args, str); - fprintf(stderr, "LibClamAV Warning: "); - vfprintf(stderr, str, args); + vsnprintf(cli_buf+sz, sizeof(cli_buf)-sz, str, args); + cli_buf[sizeof(cli_buf)-1] = '\0'; + fputs(cli_buf, stderr); va_end(args); } void cli_errmsg(const char *str, ...) { va_list args; + int sz = sizeof("LibClamAV Error: ")-1; + + memcpy(cli_buf, "LibClamAV Error: ", sz); va_start(args, str); - fprintf(stderr, "LibClamAV Error: "); - vfprintf(stderr, str, args); + vsnprintf(cli_buf+sz, sizeof(cli_buf)-sz, str, args); + cli_buf[sizeof(cli_buf)-1] = '\0'; + fputs(cli_buf, stderr); va_end(args); } @@ -105,9 +115,13 @@ void cli_dbgmsg(const char *str, ...) va_list args; if(cli_debug_flag) { + int sz = sizeof("LibClamAV debug: ")-1; + + memcpy(cli_buf, "LibClamAV debug: ", sz); va_start(args, str); - fprintf(stderr, "LibClamAV debug: "); - vfprintf(stderr, str, args); + vsnprintf(cli_buf+sz, sizeof(cli_buf)-sz, str, args); + cli_buf[sizeof(cli_buf)-1] = '\0'; + fputs(cli_buf, stderr); va_end(args); } else return;
_______________________________________________ http://lurker.clamav.net/list/clamav-devel.html