kmsg: format back to previous for /dev/kmsg 16/88816/4 accepted/tizen/3.0/mobile/20161015.033718 accepted/tizen/mobile/20160927.021034 submit/tizen/20160926.022655 submit/tizen_3.0_mobile/20161015.000004
authorMichal Bloch <m.bloch@samsung.com>
Tue, 20 Sep 2016 15:21:25 +0000 (17:21 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 22 Sep 2016 00:11:46 +0000 (17:11 -0700)
 * 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: Icafebabe08f960fa7a2766b91ab2a72e8d2891b6

kernel/printk_kmsg.c

index 7a209f4..00515b8 100644 (file)
@@ -995,6 +995,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);
@@ -1064,7 +1065,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);
        }
 
        /*
@@ -1073,7 +1077,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) {
@@ -1093,6 +1098,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');