mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: matthew-lkml@newtoncomputing.co.uk
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: Linus Torvalds <torvalds@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Stop printk printing non-printable chars
Date: Sat, 19 Jun 2004 00:52:23 +0100	[thread overview]
Message-ID: <20040618235223.GB5286@newtoncomputing.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.56.0406190032290.17899@jjulnx.backbone.dif.dk>

On Sat, Jun 19, 2004 at 12:44:55AM +0200, Jesper Juhl wrote:
> On Fri, 18 Jun 2004, Linus Torvalds wrote:
> >
> > How about emitting them as \xxx, so that you see what they are. And using
> > a case-statement to make it easy and clear when to do exceptions (I think
> > we should accept \t too, no?).
> 
> Would there be any reason not to allow all the standard C escape sequences
> - true, they are hardly used atm (I see a few \f uses with grep, but not
> much else), but it's not unthinkable they could be useful somewhere in

I must admit, I don't think I've even seen a tab before (not that you'd
actually _see_ a tab). Oh, grep tells me that powernow uses it. By the
time that gets through syslog it's changed into "^I", so it would
probably be better to not actually use tabs, either (or fix syslog).

New patch below outputs as \xxx if it's not a "nice" character.  "Nice"
is now 32..126, \n and \t.


--- linux-2.6.7/kernel/printk.c.orig	2004-06-18 20:44:28.000000000 +0100
+++ linux-2.6.7/kernel/printk.c	2004-06-19 00:11:30.000000000 +0100
@@ -14,6 +14,8 @@
  *     manfreds@colorfullife.com
  * Rewrote bits to get rid of console_lock
  *	01Mar01 Andrew Morton <andrewm@uow.edu.au>
+ * Stop emit_log_char from emitting non-ASCII chars.
+ *  Matthew Newton, 18 June 2004 <matthew-lkml@newtoncomputing.co.uk>
  */
 
 #include <linux/kernel.h>
@@ -472,6 +474,17 @@
 }
 
 /*
+ * Emit character in numeric (octal) form
+ */
+static void emit_log_char_octal(char c)
+{
+	emit_log_char('\\');
+	emit_log_char(((c >> 6) & 3) + '0');
+	emit_log_char(((c >> 3) & 7) + '0');
+	emit_log_char((c & 7) + '0');
+}
+
+/*
  * Zap console related locks when oopsing. Only zap at most once
  * every 10 seconds, to leave time for slow consoles to print a
  * full oops.
@@ -538,7 +551,17 @@
 			}
 			log_level_unknown = 0;
 		}
-		emit_log_char(*p);
+		switch (*p) {
+			case '\n':
+			case '\t':
+				emit_log_char(*p);
+				break;
+			default:
+				if (*p > 31 && *p < 127)
+					emit_log_char(*p);
+				else
+					emit_log_char_octal(*p);
+		}
 		if (*p == '\n')
 			log_level_unknown = 1;
 	}



-- 
Matthew

  reply	other threads:[~2004-06-19  0:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-18 20:53 matthew-lkml
2004-06-18 21:08 ` Linus Torvalds
2004-06-18 22:44   ` Jesper Juhl
2004-06-18 23:52     ` matthew-lkml [this message]
2004-06-19  4:18       ` Willy Tarreau
2004-06-19 10:27         ` Matthias Urlichs
2004-06-19 23:00       ` Dave Jones
2004-06-19  1:23     ` Matthias Urlichs
2004-06-19  1:43       ` Jesper Juhl
2004-06-19 10:20         ` Matthias Urlichs
2004-06-18 21:32 ` Jan-Benedict Glaw
2004-06-18 21:58   ` Pekka Pietikainen
2004-06-19  0:03   ` matthew-lkml
2004-06-19  8:31     ` Jan-Benedict Glaw
2004-06-19 11:18 ` David Woodhouse
2004-06-19 15:49   ` matthew-lkml
2004-06-19 16:09     ` Arjan van de Ven
2004-06-20  2:19     ` Horst von Brand
2004-06-20 14:17     ` David Woodhouse
2004-06-20 20:06       ` Jeff Woods
2004-06-19 20:12 Albert Cahalan
2004-06-19 22:56 ` Jan-Benedict Glaw
2004-06-20  4:02 Albert Cahalan
2004-06-20  8:38 ` David Woodhouse
2004-06-20  8:49 ` Jan-Benedict Glaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040618235223.GB5286@newtoncomputing.co.uk \
    --to=matthew-lkml@newtoncomputing.co.uk \
    --cc=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome