]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: always update header when writing stdin line
authorKarel Zak <kzak@redhat.com>
Wed, 24 Feb 2016 09:40:08 +0000 (10:40 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Feb 2016 09:40:08 +0000 (10:40 +0100)
Addresses: http://bugs.debian.org/798239
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/logger.c

index e4392661203fb14a00254a3043aeffe8fd075ad2..1e893a914429f3b35fc6fcb7d91e59292bea79b6 100644 (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();