From 9280b987d87f083baea2dfc5b91a8aeb884dddce Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Wed, 28 May 2014 19:03:34 +0200 Subject: [PATCH 1/8] Update printk.c Adding new function , int type_printk(int type, const char *fmt, ...) , it will print an output and adding type , 1 : [error] . 2 [log] 3 [action] --- kernel/printk/printk.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7228258b85eca1..61cad954d572c6 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2457,7 +2457,43 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) if (pending & PRINTK_PENDING_WAKEUP) wake_up_interruptible(&log_wait); } - +int type_printk(int type, const char *fmt, ...) +{ + unsigned long flags; + va_list args; + char *buf; + int r; + switch(type){ + case 0: + /* normal type , we will print an output like the one that printk print */ + local_irq_save(flags); + buf = __get_cpu_var(printk_sched_buf); + + va_start(args, fmt); + r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); + 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); + case 1: + /* error type , we we will print the fmt and adding [error] */ + const char *all_fmt; + sprintf(all_fmt,"[Error] : %s",fmt); + local_irq_save(flags); + buf = __get_cpu_var(printk_sched_buf); + + va_start(args, all_fmt); + r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); + 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); + break; + + } + return r; +} static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = { .func = wake_up_klogd_work_func, .flags = IRQ_WORK_LAZY, From 0f689f591ed2a980d7575787c8ff68a4d1a3699c Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Thu, 29 May 2014 16:59:57 +0200 Subject: [PATCH 2/8] Update printk.c Adding new function , int type_printk(int type, const char *fmt, ...) , it will print an output and adding type , 1 : [error] . 2 [log] 3 [action] . TODO : other types . --- kernel/printk/printk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 61cad954d572c6..51ce230e9eef62 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2476,6 +2476,7 @@ int type_printk(int type, const char *fmt, ...) __this_cpu_or(printk_pending, PRINTK_PENDING_SCHED); irq_work_queue(&__get_cpu_var(wake_up_klogd_work)); local_irq_restore(flags); + break; case 1: /* error type , we we will print the fmt and adding [error] */ const char *all_fmt; From 1179faf39deba0172b3fbfd8d96a8015ce19888c Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Fri, 30 May 2014 16:49:01 +0200 Subject: [PATCH 3/8] Update printk.c adding action type , adding default type to type_printk function --- kernel/printk/printk.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 51ce230e9eef62..ab73ff32a6418e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2462,37 +2462,38 @@ int type_printk(int type, const char *fmt, ...) unsigned long flags; va_list args; char *buf; + const char *all_fmt; int r; + ocal_irq_save(flags); + buf = __get_cpu_var(printk_sched_buf); switch(type){ case 0: /* normal type , we will print an output like the one that printk print */ - local_irq_save(flags); - buf = __get_cpu_var(printk_sched_buf); - va_start(args, fmt); - r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); - 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); + r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); break; case 1: /* error type , we we will print the fmt and adding [error] */ - const char *all_fmt; - sprintf(all_fmt,"[Error] : %s",fmt); - local_irq_save(flags); - buf = __get_cpu_var(printk_sched_buf); - - va_start(args, all_fmt); - r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); - 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); + sprintf(all_fmt, "[Error] : %s", fmt); + va_start(args, all_fmt) + r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); + break; + case 2: + /* Action type , we we will print the fmt and adding [action] */ + sprintf(all_fmt, "[Action] : %s", fmt); + va_start(args, all_fmt) + r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); + break; + default: + /* no type , printing normaly */ + va_start(args, fmt); + r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); 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; } static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = { From fd7c2a78f305cb8577f430ce5296a43325c37e19 Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Fri, 30 May 2014 17:34:31 +0200 Subject: [PATCH 4/8] Update printk.c Adding EXPORT_SYMBOL(type_printk); --- kernel/printk/printk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ab73ff32a6418e..f3edeba9740eee 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2496,6 +2496,7 @@ int type_printk(int type, const char *fmt, ...) local_irq_restore(flags); return r; } +EXPORT_SYMBOL(type_printk); static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = { .func = wake_up_klogd_work_func, .flags = IRQ_WORK_LAZY, From 4b2f3fe894d910f49c8bacbc0dfda82837e7c44c Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Sun, 1 Jun 2014 16:28:29 +0200 Subject: [PATCH 5/8] Update printk.c --- kernel/printk/printk.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f3edeba9740eee..5aba96a6171960 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2457,43 +2457,42 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) if (pending & PRINTK_PENDING_WAKEUP) wake_up_interruptible(&log_wait); } -int type_printk(int type, const char *fmt, ...) +/* type_printk : printing output width types */ +asmlinkage __visible int type_printk(int type, const char *fmt, ...) { - unsigned long flags; va_list args; - char *buf; - const char *all_fmt; int r; - ocal_irq_save(flags); - buf = __get_cpu_var(printk_sched_buf); + char *all_fmt; + switch(type){ case 0: - /* normal type , we will print an output like the one that printk print */ + /* normal type , we will print an output like the one that printk prints */ va_start(args, fmt); - r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); + 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)+10*sizeof(char), GFP_KERNEL); sprintf(all_fmt, "[Error] : %s", fmt); - va_start(args, all_fmt) - r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); + va_start(args, all_fmt); + r = vprintk_emit(0, -1, NULL, 0, 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)+11*sizeof(char), GFP_KERNEL); sprintf(all_fmt, "[Action] : %s", fmt); - va_start(args, all_fmt) - r = vsnprintf(buf, PRINTK_BUF_SIZE, all_fmt, args); + va_start(args, all_fmt); + r = vprintk_emit(0, -1, NULL, 0, all_fmt, args); + kfree(all_fmt); break; default: /* no type , printing normaly */ va_start(args, fmt); - r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args); + r = vprintk_emit(0, -1, NULL, 0, fmt, args); 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); From 10b77f5407ba8da1c9d824cd358834a8d3b4c3c1 Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Sun, 1 Jun 2014 16:30:33 +0200 Subject: [PATCH 6/8] Update printk.c --- kernel/printk/printk.c | 76 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aba96a6171960..f2c1dd6e1dceb6 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1694,7 +1694,45 @@ asmlinkage __visible int printk(const char *fmt, ...) return r; } EXPORT_SYMBOL(printk); +/* type_printk : printing output width types */ +asmlinkage __visible int type_printk(int type, const char *fmt, ...) +{ + va_list args; + int r; + char *all_fmt; + switch(type){ + 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)+10*sizeof(char), GFP_KERNEL); + sprintf(all_fmt, "[Error] : %s", fmt); + va_start(args, all_fmt); + r = vprintk_emit(0, -1, NULL, 0, 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)+11*sizeof(char), GFP_KERNEL); + sprintf(all_fmt, "[Action] : %s", fmt); + va_start(args, all_fmt); + r = vprintk_emit(0, -1, NULL, 0, all_fmt, args); + kfree(all_fmt); + break; + default: + /* no type , printing normaly */ + va_start(args, fmt); + r = vprintk_emit(0, -1, NULL, 0, fmt, args); + break; + } + va_end(args); + return r; +} +EXPORT_SYMBOL(type_printk); #else /* CONFIG_PRINTK */ #define LOG_LINE_MAX 0 @@ -2457,45 +2495,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) if (pending & PRINTK_PENDING_WAKEUP) wake_up_interruptible(&log_wait); } -/* type_printk : printing output width types */ -asmlinkage __visible int type_printk(int type, const char *fmt, ...) -{ - va_list args; - int r; - char *all_fmt; - switch(type){ - 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)+10*sizeof(char), GFP_KERNEL); - sprintf(all_fmt, "[Error] : %s", fmt); - va_start(args, all_fmt); - r = vprintk_emit(0, -1, NULL, 0, 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)+11*sizeof(char), GFP_KERNEL); - sprintf(all_fmt, "[Action] : %s", fmt); - va_start(args, all_fmt); - r = vprintk_emit(0, -1, NULL, 0, all_fmt, args); - kfree(all_fmt); - break; - default: - /* no type , printing normaly */ - va_start(args, fmt); - r = vprintk_emit(0, -1, NULL, 0, fmt, args); - break; - } - va_end(args); - return r; -} -EXPORT_SYMBOL(type_printk); static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = { .func = wake_up_klogd_work_func, .flags = IRQ_WORK_LAZY, From 169a518554f92084e63f3f0d84b634f873feda21 Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Sun, 1 Jun 2014 17:19:24 +0200 Subject: [PATCH 7/8] Update printk.c --- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f2c1dd6e1dceb6..95de2fc5116db4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1694,7 +1694,7 @@ asmlinkage __visible int printk(const char *fmt, ...) return r; } EXPORT_SYMBOL(printk); -/* type_printk : printing output width types */ +/* type_printk : printing output with types */ asmlinkage __visible int type_printk(int type, const char *fmt, ...) { va_list args; From 67860fdf9d18481668edabfafec8173f33de0e2a Mon Sep 17 00:00:00 2001 From: Hamza Naper Date: Thu, 5 Jun 2014 20:07:44 +0200 Subject: [PATCH 8/8] Update printk.c --- kernel/printk/printk.c | 92 ++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 95de2fc5116db4..d0cb72348fd594 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1695,44 +1695,86 @@ asmlinkage __visible int printk(const char *fmt, ...) } EXPORT_SYMBOL(printk); /* type_printk : printing output with types */ -asmlinkage __visible int type_printk(int type, const char *fmt, ...) +asmlinkage __visible int type_printk(int type, char *fmt, ...) { va_list args; - int r; + char *buf; char *all_fmt; + int r; + unsigned long flags; - switch(type){ - 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)+10*sizeof(char), GFP_KERNEL); + 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 = vprintk_emit(0, -1, NULL, 0, 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)+11*sizeof(char), GFP_KERNEL); + 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 = vprintk_emit(0, -1, NULL, 0, all_fmt, args); - kfree(all_fmt); - break; - default: - /* no type , printing normaly */ - va_start(args, 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; } - va_end(args); return r; } -EXPORT_SYMBOL(type_printk); +EXPORT_SYMBOL(type_printk_using_printk_sched); + #else /* CONFIG_PRINTK */ #define LOG_LINE_MAX 0