Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line
From: Joe Perches
Date: Wed May 20 2020 - 00:58:58 EST
On Wed, 2020-05-20 at 13:41 +0900, Sergey Senozhatsky wrote:
> On (20/05/19 12:42), Joe Perches wrote:
> > +static void __init print_cmdline(char *line)
> > +{
> > +#ifdef CONFIG_PRINTK
> > + const char *prefix = "Kernel command line";
> > + size_t len = strlen(line);
> > +
> > + while (len > PRINTK_LOG_LINE_MAX) {
> > + char *pos = line;
> > + char *last_pos = pos + PRINTK_LOG_LINE_MAX - 1;
> > + char saved_char;
> > + /* Find last space char within the maximum line length */
> > + while ((pos = memchr(pos, ' ', len - (pos - line))) &&
> > + (pos - line) < PRINTK_LOG_LINE_MAX - 1) {
>
> Don't you need to also count in the 'prefix' length?
yup.
> > + last_pos = pos;
> > + }
> > + saved_char = line[last_pos - line];
> > + line[last_pos - line] = 0;
> > + pr_notice("%s: %s\n", prefix, line);
> > + prefix = "Kernel command line (continued)";
> > + line[last_pos - line] = saved_char;
> > + len -= pos - line;
> > + line += pos - line;
> > + }
> > +
> > + pr_notice("%s: %s\n", prefix, line);
> > +#endif
> > +}
>
> I like this in general. And I agree that we better handle this
> externally, on the printk() caller side, so that printk() will
> still have sane limits and won't print a 1G string for example.
>
> I wonder if we need to export PRINTK_LOG_LINE_MAX.
I think a #define works well enough.(
> Maybe we can
> use here something rather random and much shorter instead. E.g.
> 256 chars. Hmm. How
min(some_max like 132/256, PRINTK_LOG_LINE_MAX)
would work.
> many crash/monitoring tools can get confused
> by multiple "Kernel command line" prefixes?
I doubt any as it's an init only function.