]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: add -t option to suppress timestamps
authorKarel Zak <kzak@redhat.com>
Mon, 18 Jul 2011 09:48:41 +0000 (11:48 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Jul 2011 09:48:41 +0000 (11:48 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index dd25362110548c49a61a09bb9b417cc8682f8b79..d86aceea036de5afd465b763608cb0b110af46b7 100644 (file)
@@ -92,6 +92,8 @@ to query the kernel ring buffer.  This is 16392 by default.
 at first, 8192 since 1.3.54, 16384 since 2.1.113.)
 If you have set the kernel buffer to be larger than the default
 then this option can be used to view the entire buffer.
+.IP "\fB\-t, \-\-notime\fP"
+Don't print kernel's timestampts.
 .IP "\fB\-u, \-\-userspace\fP"
 Print userspace messages.
 .IP "\fB\-V, \-\-version\fP"
index dc074b37de280fcd009c5be25342e6c9e44f5adb..867581d814354ee3cae8549dcd880afeeefb66a0 100644 (file)
@@ -98,6 +98,7 @@ static const struct dmesg_name facility_names[] =
 #define DMESG_FL_LEVEL         (1 << 2)
 #define DMESG_FL_FACILITY      (1 << 3)
 #define DMESG_FL_DECODE                (1 << 4)
+#define DMESG_FL_NOTIME                (1 << 5)
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
@@ -120,6 +121,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
                " -n, --console-level=LEVEL set level of messages printed to console\n"
                " -r, --raw                 print the raw message buffer\n"
                " -s, --buffer-size=SIZE    buffer size to query the kernel ring buffer\n"
+               " -t, --notime              don't print messages timestamp\n"
                " -u, --userspace           display userspace messages\n"
                " -V, --version             output version information and exit\n"
                " -x, --decode              decode facility and level to readable string\n\n"));
@@ -443,7 +445,22 @@ static void print_buffer(const char *buf, size_t size, int flags,
                                           isset(levels, lev)) &&
                    (fac < 0 || !(flags & DMESG_FL_FACILITY) ||
                                          isset(facilities, fac))) {
-                       size_t sz =  end - begin;
+                       size_t sz;
+
+                       if ((flags & DMESG_FL_NOTIME) && *begin == '[' &&
+                           (*(begin + 1) == ' ' || isdigit(*(begin + 1)))) {
+                               /* ignore timestamp */
+                               while (begin < end) {
+                                       begin++;
+                                       if (*(begin - 1) == ']')
+                                               break;
+                               }
+                       }
+
+                       if (*begin == ' ')
+                               begin++;
+
+                       sz =  end - begin;
 
                        if ((flags & DMESG_FL_DECODE) && lev >= 0 && fac >= 0) {
                                printf("%-6s:%-6s: ", facility_names[fac].name,
@@ -484,6 +501,7 @@ int main(int argc, char *argv[])
                { "level",         required_argument, NULL, 'l' },
                { "raw",           no_argument,       NULL, 'r' },
                { "read-clear",    no_argument,       NULL, 'c' },
+               { "notime",        no_argument,       NULL, 't' },
                { "userspace",     no_argument,       NULL, 'u' },
                { "version",       no_argument,       NULL, 'V' },
                { NULL,            0, NULL, 0 }
@@ -493,7 +511,7 @@ int main(int argc, char *argv[])
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       while ((c = getopt_long(argc, argv, "Ccdef:hkl:n:rs:uVx", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "Ccdef:hkl:n:rs:tuVx", longopts, NULL)) != -1) {
 
                if (cmd != -1 && strchr("Ccnde", c))
                        errx(EXIT_FAILURE, "%s %s",
@@ -541,6 +559,9 @@ int main(int argc, char *argv[])
                        if (bufsize < 4096)
                                bufsize = 4096;
                        break;
+               case 't':
+                       flags |= DMESG_FL_NOTIME;
+                       break;
                case 'u':
                        flags |= DMESG_FL_FACILITY;
                        for (n = 1; n < ARRAY_SIZE(facility_names); n++)