Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1413489lqt; Wed, 20 Mar 2024 03:20:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYt02M7yhKshGLUpbyPP04ROLaba41Fd/ES0GSjsVpEz1rE6XDPn13qXcdw9J1gVuyO6JzvRtutlUb0gO+q/WzdY9MATIyGbNifXovpQ== X-Google-Smtp-Source: AGHT+IH0YArx+ltr6sbCJpP1glpG12QpIObwDaEp54+cvhW37lDuZn1Sosb2SrTUiUna540uIaYR X-Received: by 2002:a17:906:abce:b0:a46:d9a0:ddd7 with SMTP id kq14-20020a170906abce00b00a46d9a0ddd7mr1026741ejb.68.1710930042309; Wed, 20 Mar 2024 03:20:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710930042; cv=pass; d=google.com; s=arc-20160816; b=ADR6IyyOuHEbXEPQLbxO+p8FyyCEeDBI+UXlzCflYrc9+Cj1qzmB03FVFmJkZrAIwc eJ1M+RuWbeHcHLuXxFSPep8P7/0u8k2ib2KrmE2xsE7oY9jhYAoogVQmJJ6AkoaJNmST EoILZcYDhET9UhssxMIrMdT/cXK5flkKkzFQR1MO2/17tavTuOD1aa1a9O+SLbS6Asjd QgASjugtjQzfrgdkPiIzXIxI8U383Dd2khtLWI8zkrGQBP09W6o3XJrlcQVn5hQI6l9x v7tUNYYMIYtAOcnl9kxZHJxqcoHoQyDRNr0+0/9c9EdTBWNwWUx7Kcvxe6Qn4wh/Lv6Q WkmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=TMBnso67DKuDswnFo5PzqffLcUZAHJg0j6YQi/mv7fs=; fh=476HqsOSm0ZyO8yrAhbuQDE32Mw2SBFL/j4Zm/AAB38=; b=fq1cLivYSYhbmVufvTvCo02vYj4Qs50eQoHqmbxbJcs3Ahqoog1a9mILOVzm7J0l/d Yc/m5RfBxDJ4Zwl080WxizR7T3Xb4JPwYTD1ewbgifGa1EPIUo60QZpsNPsrrkvrc35w f4O5yFPe7Tez9ar8UAUgR9YvY28UrerBLZZf7pt5iz6dFTgBrzYWGlmhfvOvQVF3Sw++ 19K0jFFsh4stwRPLwCJlhm0kUeyFt8iWEB54dBbvJZ7iVyCUilxTogwPgCbQmR96j49A HyaUQEuxmG65htxyjMQ5ywwWlOwSko9ADIpYPEzZenXJ6jKRO8qm0vKB5ocJQ5Lnk/98 QJMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=F5GKWIk7; arc=pass (i=1 spf=pass spfdomain=rasmusvillemoes.dk dkim=pass dkdomain=rasmusvillemoes.dk); spf=pass (google.com: domain of linux-kernel+bounces-108751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108751-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bl15-20020a170906c24f00b00a46d6738185si1805123ejb.876.2024.03.20.03.20.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 03:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=F5GKWIk7; arc=pass (i=1 spf=pass spfdomain=rasmusvillemoes.dk dkim=pass dkdomain=rasmusvillemoes.dk); spf=pass (google.com: domain of linux-kernel+bounces-108751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108751-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0E63A1F21732 for ; Wed, 20 Mar 2024 10:20:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA3573FB82; Wed, 20 Mar 2024 10:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.b="F5GKWIk7" Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB59F3FB35 for ; Wed, 20 Mar 2024 10:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710930002; cv=none; b=pZbgWQo+xNwtbbAfFBDRUNR62Nh4ZyxQWOGCeSsmBEB7Zq+Jjm4GeRqt3LiYoedyChv+UJu7/SEleNGvq/tZmnpu1Q8+VjxhwOpEjJVusnV5TALjaqD6uA6k6ujOTkHUQXyrqPxVZioplPKg16Bh6qLhl6IZHWRHMABjgAUnq5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710930002; c=relaxed/simple; bh=UV21p/GrGS9v955JiBiuiJ1PavXJwlV8g5S2FsRKxtk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=T0ejE0docXL0SiiDItcAuKq8T48GRHfunXygiU+7tujSmGJlVWa7yzbFV0dFfzhDIAcyuqKuaFOKwCmwXzbn3a0Jgjmp70UqGWqQACy0b3OZD9C0vzFe3Z3mIDaRRyIuRGSkhue0V0aVNhXwaUeQnRAa2LxlVS6uRBDIWhpXc8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rasmusvillemoes.dk; spf=pass smtp.mailfrom=rasmusvillemoes.dk; dkim=pass (1024-bit key) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.b=F5GKWIk7; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rasmusvillemoes.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rasmusvillemoes.dk Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-512b3b04995so5475919e87.3 for ; Wed, 20 Mar 2024 03:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1710929999; x=1711534799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TMBnso67DKuDswnFo5PzqffLcUZAHJg0j6YQi/mv7fs=; b=F5GKWIk7Byxmd1yL/RWhHOqKaQJvF7TWyYc0QWWzGBSPZATCjxCWseYAmZxY15OAjX wHbPoQaolWj9mFu5yRLwvfQTP8VvGlIDAvgBgUow2KQrMrZAHBoKhMPA7+rnNMK7PC7R aQ8Nuag65vRqw3C1ff21CTc4f7bXsyFKjoyVs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710929999; x=1711534799; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TMBnso67DKuDswnFo5PzqffLcUZAHJg0j6YQi/mv7fs=; b=isVJE67uAEGWsez2mb+ptdp2sRF4p3lHSSfgRzcYVrfgdGvadIS9sjQfp8s90Rzp9E hqCm9E8yyu3QMTlwpl/DwMYqphodvOLS3a4nMCe/TDfBYJhrurIlueOZenHRr3YzBXy+ UvZwARi1YWF8nn8jeDYxoo5qpSjdWWkMEpVfwINzY4h76+THkulsALWcWOGVorhVvCZ8 rxrqA04Is2FJdhivRRSkr0iXjglAHvjneHHqmOZsp/vzgMZI/Dbd0tu7m+tXRy8g0nAY zYW12EFWNVfb4sKuL3BJ1b3Wukc5vRqQs+Dgfmq5oPxtxP0/+12D84mABzWEKxiVN4r0 YVhg== X-Forwarded-Encrypted: i=1; AJvYcCXnnrvZsCWMTKf2qc83hseEz7GyG1m1Z+ThhTvv4Zf5qTM7a+nf4OgQEN6Imrhtee67HE0hZjttMTLsSAal8UoZqineSG3i6qSljNq2 X-Gm-Message-State: AOJu0Yw4h5WUNsrZX8WoYFnzPZSusAQMB6AFtldUyvnJQeOwgZNBonNW /D//bFvLmE/hOjgGPGThWOySXIPZb90Vduib6cbDfF23gTIBlAyPz3pfNI9oWJY= X-Received: by 2002:a05:6512:3fa:b0:513:cf4e:941b with SMTP id n26-20020a05651203fa00b00513cf4e941bmr1004330lfq.19.1710929998661; Wed, 20 Mar 2024 03:19:58 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id r17-20020aa7cb91000000b0056bafdda14bsm551297edt.28.2024.03.20.03.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 03:19:58 -0700 (PDT) From: Rasmus Villemoes To: Masami Hiramatsu Cc: Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH v3] bootconfig: do not put quotes on cmdline items unless necessary Date: Wed, 20 Mar 2024 11:19:52 +0100 Message-Id: <20240320101952.62135-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.40.1.1.g1c60b9335d Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Rasmus Villemoes --- v3: Add comment explaining why the quoting is conditional. v2: use strpbrk(, " \t\r\n") instead of a loop doing isspace(). init/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/init/main.c b/init/main.c index e24b0780fdff..7a5efe363938 100644 --- a/init/main.c +++ b/init/main.c @@ -324,7 +324,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) { @@ -342,8 +342,14 @@ 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); + /* + * For prettier and more readable /proc/cmdline, only + * quote the value when necessary, i.e. when it contains + * whitespace. + */ + 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; -- 2.40.1.1.g1c60b9335d