]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: implement backwardly compatible --raw for /dev/kmsg
authorKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 12:41:25 +0000 (14:41 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 12:41:25 +0000 (14:41 +0200)
.. and if you really want raw data from /dev/kmsg then use dd(1) ;-)

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index ff149a9e37fdac7b3b5b9f768a5f709608527c33..c67cfa14a6f0527ca1d1185e6b2b027a11efd622 100644 (file)
@@ -98,12 +98,23 @@ will
 print or clear the kernel ring buffer.
 .IP "\fB\-r\fR, \fB\-\-raw\fR"
 Print the raw message buffer, i.e., do not strip the log level prefixes.
+
+Note that the real raw format depends on method how
+.BR dmesg (1)
+reads kernel messages. The /dev/kmsg uses different format than
+.BR syslog (2) .
+For backward compatibility
+.BR dmesg (1)
+returns data always in
+.BR syslog (2)
+format. The real raw data from /dev/kmsg is possible to read for example by
+command 'dd if=/dev/kmsg iflag=nonblock'.
 .IP "\fB\-S\fR, \fB\-\-syslog\fR"
 Force to use
-.BR syslog(2)
+.BR syslog (2)
 kernel interface to read kernel messages. The default is to use /dev/kmsg rather
 than
-.BR syslog(2)
+.BR syslog (2)
 since kernel 3.5.0.
 .IP "\fB\-s\fR, \fB\-\-buffer-size \fIsize\fR
 Use a buffer of
index 70c0a2e7114f0780f073d5a6fa063938be408410..65ace3e81679434d4f0516cac95555467d790371 100644 (file)
@@ -702,6 +702,16 @@ static void print_record(struct dmesg_control *ctl, struct dmesg_record *rec)
                return;
        }
 
+       if (ctl->raw) {
+               /* compose syslog(2) compatible output */
+               printf("<%d>[%5d.%06d] ",
+                       LOG_MAKEPRI(rec->facility, rec->level),
+                       (int) rec->tv.tv_sec,
+                       (int) rec->tv.tv_usec);
+
+               goto mesg;
+       }
+
        if (ctl->decode && rec->level >= 0 && rec->facility >= 0)
                printf("%-6s:%-6s: ", facility_names[rec->facility].name,
                                      level_names[rec->level].name);
@@ -744,6 +754,7 @@ static void print_record(struct dmesg_control *ctl, struct dmesg_record *rec)
            !ctl->notime && !ctl->delta && !ctl->ctime)
                printf("[%5d.%06d] ", (int) rec->tv.tv_sec, (int) rec->tv.tv_usec);
 
+mesg:
        safe_fwrite(rec->mesg, rec->mesg_size, stdout);
 
        if (*(rec->mesg + rec->mesg_size - 1) != '\n')
@@ -893,6 +904,7 @@ static int read_kmsg(struct dmesg_control *ctl)
 
                if (parse_kmsg_record(ctl, &rec, buf, (size_t) sz) != 0)
                        continue;
+
                print_record(ctl, &rec);
        } while (1);