Commit 4bb0057f996b1491f93a64879f4c53c83bc0f0c7
Exists in
master
and in
7 other branches
Merge branch 'core/printk' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'core/printk' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, generic: mark early_printk as asmlinkage printk: export console_drivers printk: remember the message level for multi-line output printk: refactor processing of line severity tokens printk: don't prefer unsuited consoles on registration printk: clean up recursion check related static variables namespacecheck: more kernel/printk.c fixes namespacecheck: fix kernel printk.c
Showing 3 changed files Side-by-side Diff
arch/x86/kernel/early_printk.c
include/linux/kernel.h
... | ... | @@ -187,9 +187,6 @@ |
187 | 187 | __attribute__ ((format (printf, 1, 0))); |
188 | 188 | asmlinkage int printk(const char * fmt, ...) |
189 | 189 | __attribute__ ((format (printf, 1, 2))) __cold; |
190 | -extern int log_buf_get_len(void); | |
191 | -extern int log_buf_read(int idx); | |
192 | -extern int log_buf_copy(char *dest, int idx, int len); | |
193 | 190 | |
194 | 191 | extern int printk_ratelimit_jiffies; |
195 | 192 | extern int printk_ratelimit_burst; |
... | ... | @@ -205,9 +202,6 @@ |
205 | 202 | static inline int printk(const char *s, ...) |
206 | 203 | __attribute__ ((format (printf, 1, 2))); |
207 | 204 | static inline int __cold printk(const char *s, ...) { return 0; } |
208 | -static inline int log_buf_get_len(void) { return 0; } | |
209 | -static inline int log_buf_read(int idx) { return 0; } | |
210 | -static inline int log_buf_copy(char *dest, int idx, int len) { return 0; } | |
211 | 205 | static inline int printk_ratelimit(void) { return 0; } |
212 | 206 | static inline int __printk_ratelimit(int ratelimit_jiffies, \ |
213 | 207 | int ratelimit_burst) { return 0; } |
... | ... | @@ -216,7 +210,7 @@ |
216 | 210 | { return false; } |
217 | 211 | #endif |
218 | 212 | |
219 | -extern void __attribute__((format(printf, 1, 2))) | |
213 | +extern void asmlinkage __attribute__((format(printf, 1, 2))) | |
220 | 214 | early_printk(const char *fmt, ...); |
221 | 215 | |
222 | 216 | unsigned long int_sqrt(unsigned long); |
kernel/printk.c
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 | /* |
39 | 39 | * Architectures can override it: |
40 | 40 | */ |
41 | -void __attribute__((weak)) early_printk(const char *fmt, ...) | |
41 | +void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...) | |
42 | 42 | { |
43 | 43 | } |
44 | 44 | |
... | ... | @@ -235,7 +235,7 @@ |
235 | 235 | /* |
236 | 236 | * Return the number of unread characters in the log buffer. |
237 | 237 | */ |
238 | -int log_buf_get_len(void) | |
238 | +static int log_buf_get_len(void) | |
239 | 239 | { |
240 | 240 | return logged_chars; |
241 | 241 | } |
... | ... | @@ -272,19 +272,6 @@ |
272 | 272 | } |
273 | 273 | |
274 | 274 | /* |
275 | - * Extract a single character from the log buffer. | |
276 | - */ | |
277 | -int log_buf_read(int idx) | |
278 | -{ | |
279 | - char ret; | |
280 | - | |
281 | - if (log_buf_copy(&ret, idx, 1) == 1) | |
282 | - return ret; | |
283 | - else | |
284 | - return -1; | |
285 | -} | |
286 | - | |
287 | -/* | |
288 | 275 | * Commands to do_syslog: |
289 | 276 | * |
290 | 277 | * 0 -- Close the log. Currently a NOP. |
291 | 278 | |
292 | 279 | |
293 | 280 | |
... | ... | @@ -669,18 +656,17 @@ |
669 | 656 | spin_unlock(&logbuf_lock); |
670 | 657 | return retval; |
671 | 658 | } |
659 | +static const char recursion_bug_msg [] = | |
660 | + KERN_CRIT "BUG: recent printk recursion!\n"; | |
661 | +static int recursion_bug; | |
662 | + static int new_text_line = 1; | |
663 | +static char printk_buf[1024]; | |
672 | 664 | |
673 | -static const char printk_recursion_bug_msg [] = | |
674 | - KERN_CRIT "BUG: recent printk recursion!\n"; | |
675 | -static int printk_recursion_bug; | |
676 | - | |
677 | 665 | asmlinkage int vprintk(const char *fmt, va_list args) |
678 | 666 | { |
679 | - static int log_level_unknown = 1; | |
680 | - static char printk_buf[1024]; | |
681 | - | |
682 | - unsigned long flags; | |
683 | 667 | int printed_len = 0; |
668 | + int current_log_level = default_message_loglevel; | |
669 | + unsigned long flags; | |
684 | 670 | int this_cpu; |
685 | 671 | char *p; |
686 | 672 | |
... | ... | @@ -703,7 +689,7 @@ |
703 | 689 | * it can be printed at the next appropriate moment: |
704 | 690 | */ |
705 | 691 | if (!oops_in_progress) { |
706 | - printk_recursion_bug = 1; | |
692 | + recursion_bug = 1; | |
707 | 693 | goto out_restore_irqs; |
708 | 694 | } |
709 | 695 | zap_locks(); |
710 | 696 | |
711 | 697 | |
712 | 698 | |
713 | 699 | |
714 | 700 | |
715 | 701 | |
716 | 702 | |
717 | 703 | |
718 | 704 | |
... | ... | @@ -713,70 +699,62 @@ |
713 | 699 | spin_lock(&logbuf_lock); |
714 | 700 | printk_cpu = this_cpu; |
715 | 701 | |
716 | - if (printk_recursion_bug) { | |
717 | - printk_recursion_bug = 0; | |
718 | - strcpy(printk_buf, printk_recursion_bug_msg); | |
719 | - printed_len = sizeof(printk_recursion_bug_msg); | |
702 | + if (recursion_bug) { | |
703 | + recursion_bug = 0; | |
704 | + strcpy(printk_buf, recursion_bug_msg); | |
705 | + printed_len = sizeof(recursion_bug_msg); | |
720 | 706 | } |
721 | 707 | /* Emit the output into the temporary buffer */ |
722 | 708 | printed_len += vscnprintf(printk_buf + printed_len, |
723 | 709 | sizeof(printk_buf) - printed_len, fmt, args); |
724 | 710 | |
711 | + | |
725 | 712 | /* |
726 | 713 | * Copy the output into log_buf. If the caller didn't provide |
727 | 714 | * appropriate log level tags, we insert them here |
728 | 715 | */ |
729 | 716 | for (p = printk_buf; *p; p++) { |
730 | - if (log_level_unknown) { | |
731 | - /* log_level_unknown signals the start of a new line */ | |
717 | + if (new_text_line) { | |
718 | + /* If a token, set current_log_level and skip over */ | |
719 | + if (p[0] == '<' && p[1] >= '0' && p[1] <= '7' && | |
720 | + p[2] == '>') { | |
721 | + current_log_level = p[1] - '0'; | |
722 | + p += 3; | |
723 | + printed_len -= 3; | |
724 | + } | |
725 | + | |
726 | + /* Always output the token */ | |
727 | + emit_log_char('<'); | |
728 | + emit_log_char(current_log_level + '0'); | |
729 | + emit_log_char('>'); | |
730 | + printed_len += 3; | |
731 | + new_text_line = 0; | |
732 | + | |
732 | 733 | if (printk_time) { |
733 | - int loglev_char; | |
734 | + /* Follow the token with the time */ | |
734 | 735 | char tbuf[50], *tp; |
735 | 736 | unsigned tlen; |
736 | 737 | unsigned long long t; |
737 | 738 | unsigned long nanosec_rem; |
738 | 739 | |
739 | - /* | |
740 | - * force the log level token to be | |
741 | - * before the time output. | |
742 | - */ | |
743 | - if (p[0] == '<' && p[1] >='0' && | |
744 | - p[1] <= '7' && p[2] == '>') { | |
745 | - loglev_char = p[1]; | |
746 | - p += 3; | |
747 | - printed_len -= 3; | |
748 | - } else { | |
749 | - loglev_char = default_message_loglevel | |
750 | - + '0'; | |
751 | - } | |
752 | 740 | t = cpu_clock(printk_cpu); |
753 | 741 | nanosec_rem = do_div(t, 1000000000); |
754 | - tlen = sprintf(tbuf, | |
755 | - "<%c>[%5lu.%06lu] ", | |
756 | - loglev_char, | |
757 | - (unsigned long)t, | |
758 | - nanosec_rem/1000); | |
742 | + tlen = sprintf(tbuf, "[%5lu.%06lu] ", | |
743 | + (unsigned long) t, | |
744 | + nanosec_rem / 1000); | |
759 | 745 | |
760 | 746 | for (tp = tbuf; tp < tbuf + tlen; tp++) |
761 | 747 | emit_log_char(*tp); |
762 | 748 | printed_len += tlen; |
763 | - } else { | |
764 | - if (p[0] != '<' || p[1] < '0' || | |
765 | - p[1] > '7' || p[2] != '>') { | |
766 | - emit_log_char('<'); | |
767 | - emit_log_char(default_message_loglevel | |
768 | - + '0'); | |
769 | - emit_log_char('>'); | |
770 | - printed_len += 3; | |
771 | - } | |
772 | 749 | } |
773 | - log_level_unknown = 0; | |
750 | + | |
774 | 751 | if (!*p) |
775 | 752 | break; |
776 | 753 | } |
754 | + | |
777 | 755 | emit_log_char(*p); |
778 | 756 | if (*p == '\n') |
779 | - log_level_unknown = 1; | |
757 | + new_text_line = 1; | |
780 | 758 | } |
781 | 759 | |
782 | 760 | /* |
... | ... | @@ -1179,8 +1157,11 @@ |
1179 | 1157 | console->index = 0; |
1180 | 1158 | if (console->setup == NULL || |
1181 | 1159 | console->setup(console, NULL) == 0) { |
1182 | - console->flags |= CON_ENABLED | CON_CONSDEV; | |
1183 | - preferred_console = 0; | |
1160 | + console->flags |= CON_ENABLED; | |
1161 | + if (console->device) { | |
1162 | + console->flags |= CON_CONSDEV; | |
1163 | + preferred_console = 0; | |
1164 | + } | |
1184 | 1165 | } |
1185 | 1166 | } |
1186 | 1167 |