From: Karel Zak Date: Mon, 18 Jul 2011 09:48:41 +0000 (+0200) Subject: dmesg: add -t option to suppress timestamps X-Git-Tag: v2.20-rc1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d74b8dfc705216330f755519676524a57fe454c4;p=thirdparty%2Futil-linux.git dmesg: add -t option to suppress timestamps Signed-off-by: Karel Zak --- diff --git a/sys-utils/dmesg.1 b/sys-utils/dmesg.1 index dd25362110..d86aceea03 100644 --- a/sys-utils/dmesg.1 +++ b/sys-utils/dmesg.1 @@ -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" diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index dc074b37de..867581d814 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -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++)