Skip to content

Commit efee03a

Browse files
Villemoesmhiramat
authored andcommitted
bootconfig: do not put quotes on cmdline items unless necessary
When trying to migrate to using bootconfig to embed the kernel's and PID1's command line with the kernel image itself, and so allowing changing that without modifying the bootloader, I noticed that /proc/cmdline changed from e.g. console=ttymxc0,115200n8 cma=128M quiet -- --log-level=notice to console="ttymxc0,115200n8" cma="128M" quiet -- --log-level="notice" The kernel parameters are parsed just fine, and the quotes are indeed stripped from the actual argv[] given to PID1. However, the quoting doesn't really serve any purpose and looks excessive, and might confuse some (naive) userspace tool trying to parse /proc/cmdline. So do not quote the value unless it contains whitespace. Link: https://lore.kernel.org/all/20240308124401.1702046-1-linux@rasmusvillemoes.dk/ Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 46dad3c commit efee03a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

init/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
327327
{
328328
struct xbc_node *knode, *vnode;
329329
char *end = buf + size;
330-
const char *val;
330+
const char *val, *q;
331331
int ret;
332332

333333
xbc_node_for_each_key_value(root, knode, val) {
@@ -345,8 +345,9 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
345345
continue;
346346
}
347347
xbc_array_for_each_value(vnode, val) {
348-
ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ",
349-
xbc_namebuf, val);
348+
q = strpbrk(val, " \t\r\n") ? "\"" : "";
349+
ret = snprintf(buf, rest(buf, end), "%s=%s%s%s ",
350+
xbc_namebuf, q, val, q);
350351
if (ret < 0)
351352
return ret;
352353
buf += ret;

0 commit comments

Comments
 (0)