Commit acc8fa41 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

printk: add generic functions to find KERN_<LEVEL> headers

The current form of a KERN_<LEVEL> is "<.>".

Add printk_get_level and printk_skip_level functions to handle these
formats.

These functions centralize tests of KERN_<LEVEL> so a future modification
can change the KERN_<LEVEL> style and shorten the number of bytes consumed
by these headers.

[akpm@linux-foundation.org: fix build error and warning]
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Wu Fengguang <wfg@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cdf53441
...@@ -24,6 +24,32 @@ extern const char linux_proc_banner[]; ...@@ -24,6 +24,32 @@ extern const char linux_proc_banner[];
*/ */
#define KERN_CONT "<c>" #define KERN_CONT "<c>"
static inline int printk_get_level(const char *buffer)
{
if (buffer[0] == '<' && buffer[1] && buffer[2] == '>') {
switch (buffer[1]) {
case '0' ... '7':
case 'd': /* KERN_DEFAULT */
case 'c': /* KERN_CONT */
return buffer[1];
}
}
return 0;
}
static inline const char *printk_skip_level(const char *buffer)
{
if (printk_get_level(buffer)) {
switch (buffer[1]) {
case '0' ... '7':
case 'd': /* KERN_DEFAULT */
case 'c': /* KERN_CONT */
return buffer + 3;
}
}
return buffer;
}
extern int console_printk[]; extern int console_printk[];
#define console_loglevel (console_printk[0]) #define console_loglevel (console_printk[0])
......
...@@ -1487,6 +1487,7 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1487,6 +1487,7 @@ asmlinkage int vprintk_emit(int facility, int level,
size_t text_len; size_t text_len;
enum log_flags lflags = 0; enum log_flags lflags = 0;
unsigned long flags; unsigned long flags;
int kern_level;
int this_cpu; int this_cpu;
int printed_len = 0; int printed_len = 0;
...@@ -1543,17 +1544,20 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1543,17 +1544,20 @@ asmlinkage int vprintk_emit(int facility, int level,
} }
/* strip syslog prefix and extract log level or control flags */ /* strip syslog prefix and extract log level or control flags */
if (text[0] == '<' && text[1] && text[2] == '>') { kern_level = printk_get_level(text);
switch (text[1]) { if (kern_level) {
const char *end_of_header = printk_skip_level(text);
switch (kern_level) {
case '0' ... '7': case '0' ... '7':
if (level == -1) if (level == -1)
level = text[1] - '0'; level = kern_level - '0';
case 'd': /* KERN_DEFAULT */ case 'd': /* KERN_DEFAULT */
lflags |= LOG_PREFIX; lflags |= LOG_PREFIX;
case 'c': /* KERN_CONT */ case 'c': /* KERN_CONT */
text += 3; break;
text_len -= 3;
} }
text_len -= end_of_header - text;
text = (char *)end_of_header;
} }
if (level == -1) if (level == -1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment