Alessandro Vesely writes:

On Fri 30/Jan/2015 11:30:25 +0100 Szépe Viktor wrote:
> Idézem/Quoting Alessandro Vesely <[email protected]>:
>
>> Every now and then log lines from a filter through stderr to syslog get
>> intermixed.  For example, this came as a single line:
>>
>> Jan 29 13:49:35 wmail courierfilter:
>> zdkimfilter[31367]:INFO:zdkimfilter[31364]:drop
>> msg,id=00000000005DC056.0000000054CA2C5F.00007A7D: Found-Virusdrop
>> msg,id=00000000005DC04E.0000000054CA2C5F.00007A7C: Found-Virus

> Is there a \n at the end of the line written to stderr?

Yes, I have something like so:

   vfprintf(stderr, fmt, ap);
   va_end(ap);
   fputc('\n', stderr);

That "INFO:" arrived from a sibling process. They both inherit fd 2 as a pipe to courierfilter. If courierfilter had seen "INFO:" at the beginning of a line
it would have interpreted it as a severity code.  But, even if stderr is
line-buffered, two processes can happen to flush their buffers simultaneously.

Each flush is atomic. Somewhere buried in the man pages is a guarantee that if a write() to a pipe is below a certain size, it is guaranteed to be atomic, and won't get comingled with anything else that writes to the same pipe.

If stderr is line-buffered, these short log lines should not get intermingled. But is' possible that vfprintf explicitly flushes the output stream. I recall seeing that behavior somewhere, so even something like that may not work right.

The best approach is to vsnprintf the whole thing, including \n into a buffer, and manually write() it to stderr.

Attachment: pgpC35U2JmQnR.pgp
Description: PGP signature

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to