diff options
author | Mark Salyzyn <salyzyn@google.com> | 2015-05-02 17:41:27 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-05-02 17:41:27 -0500 |
commit | 38a5493031bca46263038964a8f5b188d7e9304e (patch) | |
tree | 0219b585a6376cc84d82778331a432e3f5536f84 | |
parent | 06d378325b9e7b6fd06fe45b284e189ac440345b (diff) | |
download | toybox-38a5493031bca46263038964a8f5b188d7e9304e.tar.gz |
dmesg: add -t suppress timestamp flag
-rw-r--r-- | toys/lsb/dmesg.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/toys/lsb/dmesg.c b/toys/lsb/dmesg.c index c8876757..50da8a8a 100644 --- a/toys/lsb/dmesg.c +++ b/toys/lsb/dmesg.c @@ -5,13 +5,13 @@ * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dmesg.html // We care that FLAG_c is 1, so keep c at the end. -USE_DMESG(NEWTOY(dmesg, "rs#<1n#c", TOYFLAG_BIN)) +USE_DMESG(NEWTOY(dmesg, "trs#<1n#c", TOYFLAG_BIN)) config DMESG bool "dmesg" default y help - usage: dmesg [-n LEVEL] [-s SIZE] | -c + usage: dmesg [-n LEVEL] [-s SIZE] [-r|-t] | -c Print or control the kernel ring buffer. @@ -19,6 +19,7 @@ config DMESG -n Set kernel logging LEVEL (1-9) -r Raw output (with <level markers>) -s Show the last SIZE many bytes + -t Don't print kernel's timestamps */ #define FOR_dmesg @@ -32,6 +33,9 @@ GLOBALS( void dmesg_main(void) { + if ((toys.optflags & FLAG_r) && (toys.optflags & FLAG_t)) { + error_exit("dmesg: -r and -t are mutually exclusive options"); + } // For -n just tell kernel to which messages to keep. if (toys.optflags & FLAG_n) { if (klogctl(8, NULL, TT.level)) perror_exit("klogctl"); @@ -47,12 +51,20 @@ void dmesg_main(void) if (size < 0) error_exit("klogctl"); data[size] = 0; - // Filter out level markers. + // Filter out level markers and optionally time markers if (!(toys.optflags & FLAG_r)) while ((from - data) < size) { - if ((from == data || from[-1] == '\n') && *from == '<') { - int i = stridx(from, '>'); + if (from == data || from[-1] == '\n') { + if (*from == '<') { + int i = stridx(from, '>'); + + if (i>0) from += i+1; + } + if ((*from == '[') && (toys.optflags & FLAG_t)) { + int i = stridx(from, ']'); - if (i>0) from += i+1; + if (i>0) from += i+1; + if (*from == ' ') ++from; + } } *(to++) = *(from++); } else to = data+size; |