aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2022-10-06 05:28:48 -0500
committerRob Landley <rob@landley.net>2022-10-06 05:28:48 -0500
commit62f89088fdb1c63301b15ec3502fdf70990d17cd (patch)
treed70974fb78d6152e5416dbe575d770212e0d3a44
parentb5baa040128e8cc4cda5b5e982f03a0ed92acce3 (diff)
downloadtoybox-62f89088fdb1c63301b15ec3502fdf70990d17cd.tar.gz
Fedora sticks \x09 style hex escapes into the dmesg output for some reason.
-rw-r--r--toys/lsb/dmesg.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/toys/lsb/dmesg.c b/toys/lsb/dmesg.c
index 384d6fcd..a935f700 100644
--- a/toys/lsb/dmesg.c
+++ b/toys/lsb/dmesg.c
@@ -4,10 +4,9 @@
*
* See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dmesg.html
*
- * Don't ask me why the horrible new dmesg API is still in "testing":
+ * Linux 6.0 celebrates the 10th anniversary of this being in "testing":
* http://kernel.org/doc/Documentation/ABI/testing/dev-kmsg
-// We care that FLAG_c is 1, so keep c at the end.
USE_DMESG(NEWTOY(dmesg, "w(follow)CSTtrs#<1n#c[!Ttr][!Cc][!Sw]", TOYFLAG_BIN))
config DMESG
@@ -48,7 +47,7 @@ static void color(int c)
static void format_message(char *msg, int new)
{
unsigned long long time_s, time_us;
- int facpri, subsystem, pos;
+ int facpri, subsystem, pos, ii, jj, in, out;
char *p, *text;
// The new /dev/kmsg and the old syslog(2) formats differ slightly.
@@ -72,6 +71,12 @@ static void format_message(char *msg, int new)
if (FLAG(r)) {
color(0);
printf("<%d>", facpri);
+ } else for (in = out = subsystem;; ) {
+ jj = 0;
+ if (text[in]=='\\'&& 1==sscanf(text+in, "\\x%2x%n", &ii, &jj) && jj==4) {
+ in += 4;
+ text[out++] = ii;
+ } else if (!(text[out++] = text[in++])) break;
}
// Format the time.
@@ -158,7 +163,7 @@ klogctl_mode:
// Figure out how much data we need, and fetch it.
if (!(size = TT.s)) size = xklogctl(10, 0, 0);
data = from = xmalloc(size+1);
- data[size = xklogctl(3+FLAG(c), data, size)] = 0;
+ data[size = xklogctl(3+!!FLAG(c), data, size)] = 0;
// Send each line to format_message.
to = data + size;