summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichal Bloch <m.bloch@samsung.com>2016-09-20 16:05:51 +0200
committerSeung-Woo Kim <sw0312.kim@samsung.com>2016-12-14 13:52:18 +0900
commitc2e682c41250581a178db624712857ecda99db94 (patch)
tree7c994687c4f8e5727a728aea22f2b78092b49d6f /kernel
parentbae6b52d8704da7e487c26c8f0e40491fe7792da (diff)
kmsg: format back to previous for /dev/kmsg
* no binary characters and no \0 at the end * done because the new format breaks various tools (such as sd-journal) * only affects prime /dev/kmsg, the additional /dev/kmsg12 etc unaffected Signed-off-by: Michal Bloch <m.bloch@samsung.com> Change-Id: Ideadbeef08f960fa7a2766b91ab2a72e8d2891b6
Diffstat (limited to 'kernel')
-rw-r--r--kernel/printk/printk.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 20ebf827e858..175cb13e8cd7 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -923,6 +923,7 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
char cont = '-';
size_t len;
ssize_t ret;
+ const int prime = (log_b == &log_buf);
p = user->buf;
e = user->buf + sizeof(user->buf);
@@ -930,6 +931,7 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
ret = mutex_lock_interruptible(&user->lock);
if (ret)
return ret;
+
raw_spin_lock_irq(&log_b->lock);
while (user->seq == log_b->next_seq) {
if (file->f_flags & O_NONBLOCK) {
@@ -992,7 +994,10 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
for (i = 0; i < msg->text_len; i++) {
unsigned char c = log_text(msg)[i];
- append_char(&p, e, c);
+ if (prime && (c < ' ' || c >= 127 || c == '\\'))
+ p += scnprintf(p, e - p, "\\x%02x", c);
+ else
+ append_char(&p, e, c);
}
/*
@@ -1001,7 +1006,8 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
* to security: else one could forge dictionary tags through the message
* such as "text\n _PID=123"
*/
- append_char(&p, e, '\0');
+ if (!prime)
+ append_char(&p, e, '\0');
append_char(&p, e, '\n');
if (msg->dict_len) {
@@ -1021,6 +1027,11 @@ static ssize_t kmsg_read(struct log_buffer *log_b, struct file *file,
continue;
}
+ if (prime && (c < ' ' || c >= 127 || c == '\\')) {
+ p += scnprintf(p, e - p, "\\x%02x", c);
+ continue;
+ }
+
append_char(&p, e, c);
}
append_char(&p, e, '\n');