logger: always update header when writing stdin line

Addresses: http://bugs.debian.org/798239
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2016-02-24 10:40:08 +01:00
parent 334e5eba9e
commit 7db029e54a
1 changed files with 11 additions and 2 deletions

View File

@ -905,6 +905,11 @@ static void logger_command_line(const struct logger_ctl *ctl, char **argv)
static void logger_stdin(struct logger_ctl *ctl)
{
/* note: we re-generate the the syslog header for each log message to
* update header timestamps and to reflect possible priority changes.
* The initial header is generated by logger_open().
*/
int has_header = 1;
int default_priority = ctl->pri;
int last_pri = default_priority;
size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
@ -935,7 +940,7 @@ static void logger_stdin(struct logger_ctl *ctl)
ctl->pri = default_priority;
if (ctl->pri != last_pri) {
generate_syslog_header(ctl);
has_header = 0;
max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
last_pri = ctl->pri;
}
@ -950,8 +955,12 @@ static void logger_stdin(struct logger_ctl *ctl)
}
buf[i] = '\0';
if (i > 0 || !ctl->skip_empty_lines)
if (i > 0 || !ctl->skip_empty_lines) {
if (!has_header)
generate_syslog_header(ctl);
write_output(ctl, buf);
has_header = 0;
}
if (c == '\n') /* discard line terminator */
c = getchar();