]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: fix for non-CONFIG_PRINTK_TIME kernels
authorKarel Zak <kzak@redhat.com>
Wed, 31 Aug 2011 10:28:39 +0000 (12:28 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Oct 2011 12:22:26 +0000 (14:22 +0200)
 * dmesg(1) incorrectly assumes that lines like "<6>\n"
   are broken.

 * it's more robust to assume the end of the record is "\n<"

 * print \n for empty lines

Reported-by: "Gabor Z. Papp" <gzp@papp.hu>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index 6090f4e67ce4165cd8d25e1c3b793b88164c2563..8e7bb4b69f412dc67127963acc30610cff05c432 100644 (file)
@@ -442,12 +442,12 @@ static int get_next_record(struct dmesg_control *ctl, struct dmesg_record *rec)
 
                if (!begin)
                        begin = p;
-               if (*p == '\n')
-                       end = p;
                if (i + 1 == rec->next_size) {
                        end = p + 1;
                        i++;
-               }
+               } else if (*p == '\n' && *(p + 1) == '<')
+                       end = p;
+
                if (begin && !*begin)
                        begin = NULL;   /* zero(s) at the end of the buffer? */
                if (!begin || !end)
@@ -469,9 +469,6 @@ static int get_next_record(struct dmesg_control *ctl, struct dmesg_record *rec)
                        }
                }
 
-               if (end <= begin)
-                       return -1;      /* error */
-
                if (*begin == '[' && (*(begin + 1) == ' ' ||
                                      isdigit(*(begin + 1)))) {
                        if (ctl->delta || ctl->ctime) {
@@ -534,12 +531,15 @@ static void print_buffer(const char *buf, size_t size,
        }
 
        while (get_next_record(ctl, &rec) == 0) {
-               if (!rec.mesg_size)
-                       continue;
 
                if (!accept_record(ctl, &rec))
                        continue;
 
+               if (!rec.mesg_size) {
+                       putchar('\n');
+                       continue;
+               }
+
                if (ctl->decode && rec.level >= 0 && rec.facility >= 0)
                        printf("%-6s:%-6s: ", facility_names[rec.facility].name,
                                              level_names[rec.level].name);