History

printk: suppress empty continuation lines

We have a fairly common pattern where you print several things as continuations on one single line in a loop, and then at the end you do printk(KERN_CONT "\n"); to flush the buffered output. But if the output was flushed by something else (concurrent printk activity, or just system logging), we don't want that final flushing to just print an empty line. So just suppress empty continuation lines when they couldn't be merged into the line they are a continuation of.

Linus Torvalds committed 10 years ago

Commit 8835ca51 parent 63ae6021 file · +4 −0Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/printk/printk.c+4−0
@@ -1769,6 +1769,10 @@ static size_t log_output(int facility, int level, enum log_flags lflags, const c · 1768 unmodified lines
17691769 cont_flush();
17701770 }
17711771
1772+ /* Skip empty continuation lines that couldn't be added - they just flush */
1773+ if (!text_len && (lflags & LOG_CONT))
1774+ return 0;
1775+
17721776 /* If it doesn't end in a newline, try to buffer the current line */
17731777 if (!(lflags & LOG_NEWLINE)) {
17741778 if (cont_add(facility, level, lflags, text, text_len))