[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/3] dmesg: handle multi-char log levels
From:       Peter Korsgaard <jacmet () sunsite ! dk>
Date:       2012-12-18 19:49:18
Message-ID: 1355860160-8676-2-git-send-email-jacmet () sunsite ! dk
[Download RAW message or body]

Since Linux 3.5 (7ff9554bb5: printk: convert byte-buffer to variable-length
record buffer), klog buffer can now contain log lines with multi-char
loglevel indicators (<[0-9]+>) - So we can no longer just skip 3 bytes.

Instead skip up to the terminating '>' like util-linux does.

function                                             old     new   delta
dmesg_main                                           266     280     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
 util-linux/dmesg.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index 6505da5..8641ed6 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -59,16 +59,15 @@ int dmesg_main(int argc UNUSED_PARAM, char **argv)
 		int last = '\n';
 		int in = 0;
 
-		/* Skip <#> at the start of lines */
+		/* Skip <[0-9]+> at the start of lines */
 		while (1) {
 			if (last == '\n' && buf[in] == '<') {
-				in += 3;
-				if (in >= len)
-					break;
+				while (buf[++in] != '>' && in < len)
+					;
+			} else {
+				last = buf[in++];
+				putchar(last);
 			}
-			last = buf[in];
-			putchar(last);
-			in++;
 			if (in >= len)
 				break;
 		}
-- 
1.7.10.4

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic