linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] cowsay support
@ 2018-04-01  8:56 Richard Weinberger
  2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-04-01  8:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky,
	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/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(-)

-- 
2.13.6

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] lib: vsprintf: Implement %pCOW
  2018-04-01  8:56 [PATCH 0/2] cowsay support Richard Weinberger
@ 2018-04-01  8:56 ` Richard Weinberger
  2018-04-01  9:15   ` Adam Borowski
  2018-04-02 14:18   ` Andy Shevchenko
  2018-04-01  8:56 ` [PATCH 2/2] printk: Use %pCOW for kmsg Richard Weinberger
  2018-04-02  1:57 ` [PATCH 0/2] cowsay support Sergey Senozhatsky
  2 siblings, 2 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-04-01  8:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky,
	Richard Weinberger

Add a new format string to print in cowsay format.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 lib/vsprintf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7a708f82559..a48df6f1c3f0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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,
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] printk: Use %pCOW for kmsg
  2018-04-01  8:56 [PATCH 0/2] cowsay support Richard Weinberger
  2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
@ 2018-04-01  8:56 ` Richard Weinberger
  2018-04-02  1:57 ` [PATCH 0/2] cowsay support Sergey Senozhatsky
  2 siblings, 0 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-04-01  8:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky,
	Richard Weinberger

...userspace likes eye candy.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 kernel/printk/printk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index f274fbef821d..42ea0a18081d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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;
 }
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
  2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
@ 2018-04-01  9:15   ` Adam Borowski
  2018-04-01  9:18     ` Richard Weinberger
  2018-04-02 14:18   ` Andy Shevchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Adam Borowski @ 2018-04-01  9:15 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-kernel, rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky

On Sun, Apr 01, 2018 at 10:56:21AM +0200, Richard Weinberger wrote:
> +		.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!
-- 
ᛊᚨᚾᛁᛏᚣ᛫ᛁᛊ᛫ᚠᛟᚱ᛫ᚦᛖ᛫ᚹᛖᚨᚲ

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
  2018-04-01  9:15   ` Adam Borowski
@ 2018-04-01  9:18     ` Richard Weinberger
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-04-01  9:18 UTC (permalink / raw)
  To: Adam Borowski
  Cc: linux-kernel, rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky

Am Sonntag, 1. April 2018, 11:15:49 CEST schrieb Adam Borowski:
> On Sun, Apr 01, 2018 at 10:56:21AM +0200, Richard Weinberger wrote:
> > +		.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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] cowsay support
  2018-04-01  8:56 [PATCH 0/2] cowsay support Richard Weinberger
  2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
  2018-04-01  8:56 ` [PATCH 2/2] printk: Use %pCOW for kmsg Richard Weinberger
@ 2018-04-02  1:57 ` Sergey Senozhatsky
  2 siblings, 0 replies; 8+ messages in thread
From: Sergey Senozhatsky @ 2018-04-02  1:57 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-kernel, rostedt, pantelis.antoniou, mark.rutland, pmladek,
	andriy.shevchenko, joe, corbet, me, sergey.senozhatsky

On (04/01/18 10:56), Richard Weinberger wrote:
> 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
> 

   ___________________________________________________________
 < Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> >
   -----------------------------------------------------------
                     \   ^__^
                      \  (oo)\_______
                         (__)\       )\/\
                             ||----w |
                             ||     ||

	-ss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
  2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
  2018-04-01  9:15   ` Adam Borowski
@ 2018-04-02 14:18   ` Andy Shevchenko
  2018-04-03  9:15     ` Petr Mladek
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2018-04-02 14:18 UTC (permalink / raw)
  To: Richard Weinberger, linux-kernel
  Cc: rostedt, pantelis.antoniou, mark.rutland, pmladek, joe, corbet,
	me, sergey.senozhatsky

On Sun, 2018-04-01 at 10:56 +0200, Richard Weinberger wrote:
> Add a new format string to print in cowsay format.
> 

Apparently NAK b/c missed test cases!

> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
>  lib/vsprintf.c | 52
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index d7a708f82559..a48df6f1c3f0 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -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,

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] lib: vsprintf: Implement %pCOW
  2018-04-02 14:18   ` Andy Shevchenko
@ 2018-04-03  9:15     ` Petr Mladek
  0 siblings, 0 replies; 8+ messages in thread
From: Petr Mladek @ 2018-04-03  9:15 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Richard Weinberger, linux-kernel, rostedt, pantelis.antoniou,
	mark.rutland, joe, corbet, me, sergey.senozhatsky

On Mon 2018-04-02 17:18:12, Andy Shevchenko wrote:
> On Sun, 2018-04-01 at 10:56 +0200, Richard Weinberger wrote:
> > 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-04-03  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-01  8:56 [PATCH 0/2] cowsay support Richard Weinberger
2018-04-01  8:56 ` [PATCH 1/2] lib: vsprintf: Implement %pCOW Richard Weinberger
2018-04-01  9:15   ` Adam Borowski
2018-04-01  9:18     ` Richard Weinberger
2018-04-02 14:18   ` Andy Shevchenko
2018-04-03  9:15     ` Petr Mladek
2018-04-01  8:56 ` [PATCH 2/2] printk: Use %pCOW for kmsg Richard Weinberger
2018-04-02  1:57 ` [PATCH 0/2] cowsay support Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).