debug: Avoid debug header being separated from debug text
authorMartin Schwenke <martin@meltin.net>
Sat, 3 Dec 2016 01:27:47 +0000 (12:27 +1100)
committerVolker Lendecke <vl@samba.org>
Thu, 14 Oct 2021 10:21:30 +0000 (10:21 +0000)
commit9f8be709c4951f2af8797f175555c6b861ea6fa4
tree96fefa01782b67f2cfe4bba21e97b08ea583d3ba
parent10f68148a9716fd06ac58d0b69783a4fac30c2bc
debug: Avoid debug header being separated from debug text

Currently the file backend can produce something like:

  HEADER1 HEADER2  TEXT2
    TEXT1

when different processes try to log at the same time.

Avoid this by writing the header and text at the same time using
writev().  This means that the header always has to be written by the
backend, so update all backends to do this.

The non-file backends should behave as before when they were invoked
separately to render the header.  It might be possible to optimise
some of them (e.g. via sd_journal_sendv) but this requires more
investigation (e.g. sd_journal_sendv()'s handling of newlines) and is
beyond the scope of this change.

state.header_str_no_nl takes the place of msg_no_nl for the header,
since some of the backends need the no-newline version.  It is handled
the same was as msg_no_nl: produce the no_nl version exactly once,
whether or not it is needed, since this is better than repeating it in
several backends.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/util/debug.c