]> 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>
Tue, 10 Mar 2015 10:19:33 +0000 (11:19 +0100)
commit2b3f40c5978569f15e30836cf99f34f31c163d1c
tree58a62e52e4cdf0b57db8cef92ac3f324eb7c3bea
parentf68b8aa7f5dc1fdf403a2ef64b5dd86f3fdbee95
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