X-Original-To: alpine-devel@lists.alpinelinux.org Received: from sender153-mail.zoho.com (sender153-mail.zoho.com [74.201.84.153]) by lists.alpinelinux.org (Postfix) with ESMTP id 7D2865C449C for ; Tue, 29 Nov 2016 23:18:09 +0000 (GMT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=date:from:to:cc:message-id:in-reply-to:references:subject:mime-version:content-type:user-agent; b=qsqGXwvqlHcyIYb0c9nSV1QqCSkCfYUixSBuHXGWZoCsi/6R2yQ4vvIguQIiX1c0VVv7JKTgxDFE RScoz2rJx0Fn9ooUnfMb187TRnK4vn8aePieQLCxS3ww9SsIxM0R Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1480461478462691.6735373020882; Tue, 29 Nov 2016 15:17:58 -0800 (PST) Received: from [89.74.198.11] by mail.zoho.com with HTTP;Tue, 29 Nov 2016 15:17:58 -0800 (PST) Date: Wed, 30 Nov 2016 00:17:58 +0100 From: =?UTF-8?Q?Przemys=C5=82aw_Pawe=C5=82czyk?= To: "Shiz" Cc: "" , "Natanael Copa" Message-ID: <158b2616a36.b03a19706367.3199754036165045115@zoho.com> In-Reply-To: <20161117015252.27549-2-hi@shiz.me> References: <20161117015252.27549-1-hi@shiz.me> <20161117015252.27549-2-hi@shiz.me> Subject: Re: [alpine-devel] [PATCH 2/3] init: fix quoting issue for kernel arguments X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Priority: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail ---- On Thu, 17 Nov 2016 02:52:51 +0100 Shiz wrote ---- > The kernel passes arguments from /proc/cmdline as a single string like > foo=bar baz="something with spaces". In the latter case, with the added > single quotes the actual value of ${KOPT_baz} would contain these quotes > as well, which is not the intention. Description is a bit wrong. Kernel provides arguments used during boot via /proc/cmdline as a single text line. The problem is that set -- $(cat /proc/cmdline) doesn't do what you think it does (or at least what your patch assumes). There is even a comment earlier: # read the kernel options. we need surve things like: # acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0) to hint that it's not an easy matter. If you'd perform in POSIX sh: ./script acpi_osi="!Windows 2006" xen-pciback.hide='(01:00.0)' Then $1 would be equal to 'acpi_osi=!Windows 2006' and $2 would be queal to 'xen-pciback.hide=(01:00.0)' (single-quoting around value of xen-pciback.hide in ./script call was necessary to avoid interpreting of parenthesis and raising error). Both without the single-quotes, of course. (Actually in bash you'd have to change double-quoting in first argument to single-quoting too, because otherwise ! is interpreted and you get error.) But if you do: echo 'acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0)' >cmdline ./script $(cat cmdline) then: $1 = 'acpi_osi="!Windows' $2 = '2006"' $3 = 'xen-pciback.hide=(01:00.0)' All without the single-quotes, of course. so it's not what we want. We don't have information about real argument boundaries. What we need is to reassemble arguments. Something akin to recreating "$@" from $*. It's quite hard to do in POSIX sh. I spend some time yesterday and I came up with: https://gist.github.com/przemoc/168ecd5a263e1e498ee6d2ee4278e4ae It's not perfect, it's not a beauty, but I think it's very good approximation of what we need and it works (it handles many cases, but obviously not all of them - doing it in shell is more than cumbersome). The code (w/o show current arguments part) should be put after set -- $(cat /proc/cmdline), and then your patch should be reverted (i.e. single-quoting in eval KOPT_${i} assignment should be restored). I hoped to provide such patch, but it's already so late, that I won't do it today and I am merely informing about the problem. I'm also starting to doubt that ncopa will happily include additional 150 lines in initramfs-init.in, even if they work, so it may be better to get some kind of half-ACK at least before preparing the patch. Regards, Przemek > --- > initramfs-init.in | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/initramfs-init.in b/initramfs-init.in > index 78bcbe4..9aa1d3f 100755 > --- a/initramfs-init.in > +++ b/initramfs-init.in > @@ -279,7 +279,7 @@ for opt; do > > for i in $myopts; do > case "$opt" in > - $i=*) eval "KOPT_${i}='${opt#*=}'";; > + $i=*) eval "KOPT_${i}=${opt#*=}";; > $i) eval "KOPT_${i}=yes";; > no$i) eval "KOPT_${i}=no";; > esac > -- > 2.10.0 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---