lkml.org 
[lkml]   [2018]   [Sep]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] printk: inject caller information into the body of message
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

\
 
 \ /
  Last update: 2018-09-13 14:27    [W:0.197 / U:23.832 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site