Re: [PATCH] printk: inject caller information into the body of message

From: Petr Mladek
Date: Thu Sep 13 2018 - 08:26:31 EST


On Thu 2018-09-13 16:12:54, Sergey Senozhatsky wrote:
> On (09/12/18 12:05), Steven Rostedt wrote:
> > > : Introduce a few helper functions for it:
> > > :
> > > : init_line_buffer(&buf);
> > > : print_line(&buf, fmt, args);
> > > : vprint_line(&buf, fmt, vararg);
> > > : finish_line(&buf);
> > > :
> >
> --- a/lib/seq_buf.c
> +++ b/lib/seq_buf.c
> @@ -324,3 +324,49 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
> s->readpos += cnt;
> return cnt;
> }
> +
> +int vpr_line(struct pr_line *pl, const char *fmt, va_list args)
> +{
> + struct seq_buf *s = &pl->sb;
> + int ret, len;
> +
> + if (fmt[0] == '\n') {
> + pr_line_flush(pl);
> + return 0;
> + }

You would need to check if fmt[1] == '\0'. But then you would need
to be careful about a possible buffer overflow. I would personally
avoid this optimization.


> + ret = seq_buf_vprintf(s, fmt, args);
> +
> + len = seq_buf_used(s);
> + if (len && s->buffer[len - 1] == '\n')
> + pr_line_flush(pl);

This would cause that pr_line_flush() won't be strictly needed.
Also it would encourage people to use this feature a more
complicated way (for more lines). Do we really want this?


In general, I like this approach more than any attemps to handle
continuous lines transpatently. The other attemps were much more
complicated or were not reliable.

Best Regards,
Petr