summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2024-04-12 19:02:08 +0300
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>2024-04-12 19:02:08 +0300
commitefee03a50c2844d78f6fb5e98be1ffd17605dc5b (patch)
tree586189e9f9502b7373e47b06b9edb11aa4bb0492 /init
parent46dad3c1e57897ab9228332f03e1c14798d2d3b9 (diff)
downloadlinux-efee03a50c2844d78f6fb5e98be1ffd17605dc5b.tar.xz
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>
Diffstat (limited to 'init')
-rw-r--r--init/main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/init/main.c b/init/main.c
index 5dcf5274c09c..96e59e5761ff 100644
--- a/init/main.c
+++ b/init/main.c
@@ -327,7 +327,7 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
{
struct xbc_node *knode, *vnode;
char *end = buf + size;
- const char *val;
+ const char *val, *q;
int ret;
xbc_node_for_each_key_value(root, knode, val) {
@@ -345,8 +345,9 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
continue;
}
xbc_array_for_each_value(vnode, val) {
- ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ",
- xbc_namebuf, val);
+ q = strpbrk(val, " \t\r\n") ? "\"" : "";
+ ret = snprintf(buf, rest(buf, end), "%s=%s%s%s ",
+ xbc_namebuf, q, val, q);
if (ret < 0)
return ret;
buf += ret;