cowsay support
Subsystems (3)
cover cowsay support
As the printk subsystem gains more and more popularity it is time to add the final missing feature to make it perfect, namely cowsay output. Currently only one type of cow is supported and the only user is kmsg, but I can see more use cases for it and the need for different cow types.
Example of /dev/kmsg usage:
[ 1.309561] _________________________________________ [ 1.309561] < systemd[1]: Detected architecture x86-64. > [ 1.309561] ----------------------------------------- [ 1.309561] \ ^__^ [ 1.309561] \ (oo)\_______ [ 1.309561] (__)\ )\/\ [ 1.309561] ||----w | [ 1.309561] || ||
Richard Weinberger (2):
lib: vsprintf: Implement %pCOW
printk: Use %pCOW for kmsg
kernel/printk/printk.c | 5 ++++- lib/vsprintf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
Signature · 1 line
2.13.6
PATCH 1/2 lib: vsprintf: Implement %pCOW
Add a new format string to print in cowsay format.
--- lib/vsprintf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
lib/vsprintf.c +52 -0
@@ -1693,6 +1693,55 @@ static int __init initialize_ptr_random(void) }early_initcall (initialize_ptr_random); +static char *cowsay (char *buf,char *end,void *ptr) +{ +static char dashes[] = {[0 ...256 ] ='-' }; +static char unders[] = {[0 ...256 ] ='_' }; +static char spaces[] = {[0 ...256 ] =' ' }; +static struct cow_type { +int num_lines; +char *cow_lines[]; + } default_cow = { + .num_lines =5 , + .cow_lines = { +"\\ ^__^" , +" \\ (oo)\\_______" , +" (__)\\ )\\/\\" , +" ||----w |" , +" || ||" , + }, + }; + +int i, n; +char *orig_buf = buf; +char *str = ptr; +int len =strlen (str); + + n =snprintf (buf, end - buf," %.*s\n< %s >\n %.*s\n" , len, unders, + str, len, dashes); +if (n <0 || buf + n >= end) + goto cow_too_fat; + + buf += n; + +for (i =0 ; i < default_cow.num_lines; i++) { + n =snprintf (buf, end - buf,"%.*s%s\n" , len /2 , spaces, + default_cow.cow_lines[i]); +if (n <0 || buf + n >= end) + goto cow_too_fat; + + buf += n; + } + +return buf; + +cow_too_fat: + n =snprintf (orig_buf, end - orig_buf,"%s\n" , str); +if (n >0 ) + orig_buf += n; +return orig_buf; +} +/* Maps a pointer to a 32 bit unique identifier. */ static char *ptr_to_id (char *buf,char *end,void *ptr,struct printf_spec spec) {
@@ -1941,6 +1990,9 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,case 'd' :return dentry_name (buf, end, ptr, spec, fmt);case 'C' : +if (fmt[1 ] =='O' && fmt[2 ] =='W' ) +return cowsay (buf, end, ptr); +return clock (buf, end, ptr, spec, fmt);case 'D' : return dentry_name(buf, end,
Signature · 1 line
2.13.6
Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
lib/vsprintf.c static int __init initialize_ptr_random(void) · line 1711
Quoted 6 lines · Richard Weinberger
lib/vsprintf.c +6
-0+ .cow_lines = { +"\\ ^__^" , +" \\ (oo)\\_______" , +" (__)\\ )\\/\\" , +" ||----w |" , + " || ||",
Userspace cowsay(6) knows of different cows. What about using those as a visual indication of message level?
Meow! err... Moo!
Signature · 1 line
ᛊᚨᚾᛁᛏᚣ᛫ᛁᛊ᛫ᚠᛟᚱ᛫ᚦᛖ᛫ᚹᛖᚨᚲ
Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
Am Sonntag, 1. April 2018, 11:15:49 CEST schrieb Adam Borowski:
Quoted 10 lines · Richard Weinberger
lib/vsprintf.c static int __init initialize_ptr_random(void) · line 1711
Quoted 6 lines
lib/vsprintf.c +6
-0+ .cow_lines = { +"\\ ^__^" , +" \\ (oo)\\_______" , +" (__)\\ )\\/\\" , +" ||----w |" , + " || ||",Userspace cowsay(6) knows of different cows. What about using those as a visual indication of message level?
Yeah, this will be implemented for April 1st 2019 if we get funding. I think of a eBPF cow engine such that usespace can load different cow types.
Thanks,
//richard
Andy Shevchenko
reviewerRe: [PATCH 1/2] lib: vsprintf: Implement %pCOW
In reply to Richard WeinbergerQuoted 2 lines · Richard Weinberger
Add a new format string to print in cowsay format.
Apparently NAK b/c missed test cases!
Quoted 80 lines
Signed-off-by Richard Weinberger <[email protected]>--- lib/vsprintf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)lib/vsprintf.c +49
-0@@ -1693,6 +1693,55 @@ static int __init initialize_ptr_random(void) }early_initcall (initialize_ptr_random); +static char *cowsay (char *buf,char *end,void *ptr) +{ +static char dashes[] = {[0 ...256 ] ='-' }; +static char unders[] = {[0 ...256 ] ='_' }; +static char spaces[] = {[0 ...256 ] =' ' }; +static struct cow_type { +int num_lines; +char *cow_lines[]; + } default_cow = { + .num_lines =5 , + .cow_lines = { +"\\ ^__^" , +" \\ (oo)\\_______" , +" (__)\\ )\\/\\" , +" ||----w |" , +" || ||" , + }, + }; + +int i, n; +char *orig_buf = buf; +char *str = ptr; +int len =strlen (str); + + n =snprintf (buf, end - buf," %.*s\n< %s >\n %.*s\n" , len, unders, + str, len, dashes); +if (n <0 || buf + n >= end) + goto cow_too_fat; + + buf += n; + +for (i =0 ; i < default_cow.num_lines; i++) { + n =snprintf (buf, end - buf,"%.*s%s\n" , len /2 , spaces, + default_cow.cow_lines[i]); +if (n <0 || buf + n >= end) + goto cow_too_fat; + + buf += n; + } + +return buf; + +cow_too_fat: + n =snprintf (orig_buf, end - orig_buf,"%s\n" , str); +if (n >0 ) + orig_buf += n; +return orig_buf; +} +/* Maps a pointer to a 32 bit unique identifier. */ static char *ptr_to_id(char *buf, char *end, void *ptr, struct
printf_specspec)
{lib/vsprintf.c +3
-0@@ -1941,6 +1990,9 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, case 'd':return dentry_name (buf, end, ptr, spec, fmt);case 'C' : +if (fmt[1 ] =='O' && fmt[2 ] =='W' ) +return cowsay (buf, end, ptr); +return clock (buf, end, ptr, spec, fmt);case 'D' :return dentry_name(buf, end,
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Petr Mladek
maintainerRe: [PATCH 1/2] lib: vsprintf: Implement %pCOW
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Richard Weinberger
Add a new format string to print in cowsay format.
Apparently NAK b/c missed test cases!
This is really sad. I'll miss the cows.
Moo,
Petr
PATCH 2/2 printk: Use %pCOW for kmsg
In reply to Richard Weinberger...userspace likes eye candy.
--- kernel/printk/printk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/printk/printk.c +4 -1
@@ -815,7 +815,10 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from) } } -printk_emit (facility, level,NULL ,0 ,"%s" , line); +if (line[len -1 ] =='\n' ) + line[len -1 ] ='\0' ; + +printk_emit (facility, level,NULL ,0 ,"%pCOW" , line);kfree (buf);return ret; }
Signature · 1 line
2.13.6
Quoted 15 lines · Richard Weinberger
As the printk subsystem gains more and more popularity it is time to add the final missing feature to make it perfect, namely cowsay output. Currently only one type of cow is supported and the only user is kmsg, but I can see more use cases for it and the need for different cow types.
Example of
/dev/kmsgusage:[ 1.309561] _________________________________________ [ 1.309561] < systemd[1]: Detected architecture x86-64. > [ 1.309561] ----------------------------------------- [ 1.309561] \ ^__^ [ 1.309561] \ (oo)\_______ [ 1.309561] (__)\ )\/\ [ 1.309561] ||----w | [ 1.309561] || ||
Quoted 4 lines
Richard Weinberger (2):
lib: vsprintf: Implement %pCOW
printk: Use %pCOW for kmsg
___________________________________________________________
< Acked-by: Sergey Senozhatsky <[email protected]> >
-----------------------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
-ss