From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hans de Goede Date: Mon, 04 Aug 2014 20:29:33 +0200 Subject: [U-Boot] [PATCH] pxe: Allow use of environment variables in append string In-Reply-To: <53DBE56C.9020308@wwwdotorg.org> References: <1406884903-24749-1-git-send-email-hdegoede@redhat.com> <53DBE56C.9020308@wwwdotorg.org> Message-ID: <53DFD10D.6010501@redhat.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi, On 08/01/2014 09:07 PM, Stephen Warren wrote: > On 08/01/2014 03:21 AM, Hans de Goede wrote: >> Use run_command("setenv bootargs append>") so that environment >> variables (e.g. $console) can be used in append strings. > > I'm slightly worried that this changes the semantics of the append line in the PXE/extlinux config file. Namely, you suddenly have to start worrying about escaping any $ signs or semi-colons etc.. I'm not that worried about $ needing escaping, as I cannot think of any kernel commandline options using $, maybe they exist but if they do they are quite rare. But you make a good point about the ; I know some kernel cmdline options which use those... > >> diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c > >> if (!localcmd) >> return -ENOENT; >> >> - if (label->append) >> - setenv("bootargs", label->append); >> + if (label->append) { >> + bootargs = malloc(strlen("setenv bootargs ") + >> + strlen(label->append) + 1); >> + if (!bootargs) >> + return 1; > > Shouldn't this return a -ve error code for consistency with the other pre-existing error case I quoted above. Yeah this is weird, I copy pasted this from the label_boot() function, of which is a special version, also label_boot() is the only caller of label_localboot() (where this hunk applies), and it does not check the return value at all... I could make it -ENOMEM if you prefer. >> + strcpy(bootargs, "setenv bootargs "); >> + strcat(bootargs, label->append); >> + run_command(bootargs, 0); > > Using whatever C function that the shell uses to expand variable references in the command-line, rather than run_command(), would at least avoid the issue of ; in label->append causing part of label->append after the ; to be execututed as a separate command. Ack, I'll look into that and post a v2 with that change. > There would still be the issue of $ suddenly meaning something different. Right, but as said I'm not really worried about that. Regards, Hans