aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/lsb/dmesg.c24
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;