[arch-projects] [initscripts] Incorrect environment variable checks in sysinit & co?
Dave Reisner
d at falconindy.com
Thu Mar 31 19:27:34 EDT 2011
On Fri, Apr 01, 2011 at 12:40:12AM +0200, Thomas Bächler wrote:
> I just revisited [1] and found out that it isn't correct. The kernel
> only exports foo=bar pairs to init (and only if it doesn't know the left
> hand side, for instance, it doesn't export root=). Statements without =
> are not exported.
>
> The reason this worked is that mkinitcpio used 'export' to export
> 'verbose=y' in this case. This is not true anymore for 0.6.9 (and future
> releases, as 0.6.9 has a bug related to this change).
>
> I guess [1] should be reverted, and the initscripts should be search for
> more such checks.
>
> [1]
> http://projects.archlinux.org/initscripts.git/commit/?id=3d9fbd69fbab72ccdbdfda584b732636cece908c
>
Both approaches are flawed, in my opinion, because the code that was
removed would catch 'verboseforthehellofit'. In lieu of using grep's
entirely broken -w flag and \b regex markers, I suggest one of two
approaches:
1) Word split /proc/cmdline into an array and use in_array from
/etc/rc.d/functions:
kern_cmdline=($(< /proc/cmdline))
if in_array "${kern_cmdline[@]}" verbose; then
...
2) Word split /proc/cmdline with printf and use grep -x:
if printf "%s\n" $(</proc/cmdline) | grep x 'verbose'; then
...
The first approach is nice because we're not calling externals (I
believe the < acts as a builtin), but has the tradeoff of leaving an
array that we don't use. The second approach is a little cleaner, but
requires calling grep. I can't really pick a favorite here, but we
shouldn't just do a revert because I don't believe that's a proper
solution.
dave
More information about the arch-projects
mailing list