Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line

From: Sergey Senozhatsky
Date: Wed May 20 2020 - 00:41:33 EST


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?

> + 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. Maybe we can
use here something rather random and much shorter instead. E.g.
256 chars. Hmm. How many crash/monitoring tools can get confused
by multiple "Kernel command line" prefixes?

-ss