public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC V2] printk: add warning while drop partial text in msg
@ 2017-07-30 13:37 pierre Kuo
  2017-08-01  2:43 ` Sergey Senozhatsky
  0 siblings, 1 reply; 17+ messages in thread
From: pierre Kuo @ 2017-07-30 13:37 UTC (permalink / raw)
  To: pmladek; +Cc: sergey.senozhatsky, rostedt, linux-kernel, pierre Kuo

If the buffer pass to msg_print_text is not big enough to put both all
prefixes and log_text(msg), kernel will quietly break.
That means the user may not have the chance to know whether the
log_text(msg) is fully printed into buffer or not.

In this patch, once above case happened, we try to calculate how many
characters of log_text(msg) are dropped and add warning for debugging
purpose.

Signed-off-by: pierre Kuo <vichy.kuo@gmail.com>
---
Changes since v2:
 * fix typo in commit message from "waring for debugging purpose" to "warning for debugging purpose"

 kernel/printk/printk.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fc47863..6cbb3699 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -558,6 +558,12 @@ static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len)
 #define MAX_LOG_TAKE_PART 4
 static const char trunc_msg[] = "<truncated>";
 
+/*
+ * Define max drop msg length that we put in next msg
+ */
+#define MAX_DROP_MSG_LENGTH 32
+static char drop_msg[MAX_DROP_MSG_LENGTH];
+
 static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len,
 			u16 *dict_len, u32 *pad_len)
 {
@@ -1264,8 +1270,23 @@ static size_t msg_print_text(const struct printk_log *msg, bool syslog, char *bu
 
 		if (buf) {
 			if (print_prefix(msg, syslog, NULL) +
-			    text_len + 1 >= size - len)
+			    text_len + 1 >= size - len) {
+				/* below stores dropped characters
+				 * related information in next msg
+				 */
+				size_t drop_len;
+
+				drop_len = scnprintf(drop_msg,
+					MAX_DROP_MSG_LENGTH,
+					"<%u characters dropped>",
+					(next) ?
+					(unsigned int)(text_size + next - text) :
+					(unsigned int)text_size);
+				drop_msg[drop_len] = 0;
+				log_store(msg->facility, msg->level, msg->flags,
+					0, NULL, 0, drop_msg, strlen(drop_msg));
 				break;
+			}
 
 			len += print_prefix(msg, syslog, buf + len);
 			memcpy(buf + len, text, text_len);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-10-18  1:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-30 13:37 [RFC V2] printk: add warning while drop partial text in msg pierre Kuo
2017-08-01  2:43 ` Sergey Senozhatsky
2017-08-10 16:26   ` pierre kuo
2017-08-10 16:55     ` pierre kuo
2017-08-16  9:21       ` Petr Mladek
2017-08-17  1:05       ` Sergey Senozhatsky
2017-09-12  6:07         ` pierre kuo
2017-09-18  9:39           ` Sergey Senozhatsky
2017-09-18 10:00             ` Joe Perches
2017-09-18 10:08               ` Sergey Senozhatsky
2017-09-27 13:59             ` pierre kuo
2017-09-30  3:14               ` Sergey Senozhatsky
2017-10-04 13:28               ` Petr Mladek
2017-10-17 17:10                 ` pierre kuo
2017-10-18  1:07                   ` Sergey Senozhatsky
2017-10-04 13:17           ` Petr Mladek
2017-10-17 17:07             ` pierre kuo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox