]> git.ipfire.org Git - thirdparty/util-linux.git/commit
logger: refactor message generation
authorRainer Gerhards <rgerhards@adiscon.com>
Fri, 6 Mar 2015 17:52:26 +0000 (18:52 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2015 09:20:33 +0000 (10:20 +0100)
commit5d627e7fe6872c915e19431a96bb62448328ef33
tree5bb939ad72dbe6d95345c0c40f870685d66d850b
parent2a3b435d8ba7c6a5c26193102663d74abb74fcdb
logger: refactor message generation

Previously, the message format was generated in one big step. Now
this is refactored to generate the header independently. This not
only provides a better isolation of functionality, but enables
to calculate the size of the header *before* generating the user
part of the message. That in turn is needed in order to precisely
enforce the message size limit. This is especially important while
processing files, as here parts of the message may be lost if the
receiver truncates the message. The file reader itself tries to
guard against this by reading only the permitted number of bytes,
but without knowing the header size, it would mis-guess here.

Note that when --prio-prefix is given, we still do not know exactly
the header length, because the PRI value is between 1 and 3 bytes.
Unfortunately, we do not know the actual size before reading. With
the current (simple) approach, we need to read the full line before
getting the PRI, so this is a hen-egg problem. To solve this, a
more complex reader would be required. It is questionable if this
is necessary for a tool like logger. So currently, we still have a
2-byte window of uncertainty if --prio-prefix is given.

[kzak@redhat.com: - fix compiler warnings [-Wunused-but-set-variable]]

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/logger.c