Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions kernel/printk/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,86 @@ asmlinkage __visible int printk(const char *fmt, ...)
return r;
}
EXPORT_SYMBOL(printk);
/* type_printk : printing output with types */
asmlinkage __visible int type_printk(int type, char *fmt, ...)
{
va_list args;
char *buf;
char *all_fmt;
int r;
unsigned long flags;

local_irq_save(flags);
buf = __get_cpu_var(printk_sched_buf);

switch(type) {
default:
/* no type , printing normaly */
va_start(args, fmt);
r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args);
break;
case 1:
/* error type , we we will print the fmt and adding [error] */
all_fmt = kmalloc(sizeof(fmt)+11*sizeof(char), GFP_KERNEL);
sprintf(all_fmt, "[Error] : %s", fmt);
va_start(args, all_fmt);
r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args);
kfree(all_fmt);
break;
case 2:
/* Action type , we we will print the fmt and adding [action] */
all_fmt = kmalloc(sizeof(fmt)+12*sizeof(char), GFP_KERNEL);
sprintf(all_fmt, "[Action] : %s", fmt);
va_start(args, all_fmt);
r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args);
kfree(all_fmt);
break;
}
va_end(args);
__this_cpu_or(printk_pending, PRINTK_PENDING_SCHED);
irq_work_queue(&__get_cpu_var(wake_up_klogd_work));
local_irq_restore(flags);
return r;
}
EXPORT_SYMBOL(type_printk);

asmlinkage __visible int type_printk_using_printk_sched(int type, char *fmt, ...)
{
va_list args;
char *all_fmt;
int r;

switch(type) {
default:
/* no type , printing normaly */
va_start(args, fmt);
r = printk_sched(fmt, args);
break;
case 0:
/* normal type , we will print an output like the one that printk prints */
va_start(args, fmt);
r = vprintk_emit(0, -1, NULL, 0, fmt, args);
break;
case 1:
/* error type , we we will print the fmt and adding [error] */
all_fmt = kmalloc(sizeof(fmt)+11*sizeof(char), GFP_KERNEL);
sprintf(all_fmt, "[Error] : %s\n", fmt);
va_start(args, all_fmt);
r = printk_sched(all_fmt, args);
kfree(all_fmt);
break;
case 2:
/* Action type , we we will print the fmt and adding [action] */
all_fmt = kmalloc(sizeof(fmt)+12*sizeof(char), GFP_KERNEL);
sprintf(all_fmt, "[Action] : %s\n", fmt);
va_start(args, all_fmt);
r = printk_sched(all_fmt, args);
kfree(all_fmt);
break;
}
return r;
}
EXPORT_SYMBOL(type_printk_using_printk_sched);

#else /* CONFIG_PRINTK */

Expand Down