diff options
author | Michal Bloch <m.bloch@samsung.com> | 2016-09-20 16:05:51 +0200 |
---|---|---|
committer | Seung-Woo Kim <sw0312.kim@samsung.com> | 2016-12-14 13:52:18 +0900 |
commit | c2e682c41250581a178db624712857ecda99db94 (patch) | |
tree | 7c994687c4f8e5727a728aea22f2b78092b49d6f /kernel | |
parent | bae6b52d8704da7e487c26c8f0e40491fe7792da (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.c | 15 |
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'); |