pxe: Allow use of environment variables in append string
PATCH 1/1 pxe: Allow use of environment variables in append string
Use run_command("setenv bootargs <label->append>") so that environment variables (e.g. $console) can be used in append strings.
--- common/cmd_pxe.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
common/cmd_pxe.c +16 -7
@@ -571,14 +571,23 @@ static void label_print(void *data)static int label_localboot (struct pxe_label *label) {char *localcmd; +char *bootargs; localcmd =from_env ("localcmd" );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 ; +strcpy (bootargs,"setenv bootargs " ); +strcat (bootargs, label->append); +run_command (bootargs,0 ); +free (bootargs); + }debug ("running: %s\n" , localcmd);
@@ -669,17 +678,17 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) len +=strlen (label->append);if (len) { - bootargs =malloc (len +1 ); + bootargs =malloc (strlen ("setenv bootargs " ) + len +1 );if (!bootargs)return 1 ; - bootargs[0 ] ='\0' ; +strcpy (bootargs,"setenv bootargs " );if (label->append) -strcpy (bootargs, label->append); +strcat (bootargs, label->append);strcat (bootargs, ip_str);strcat (bootargs, mac_str); -setenv ("bootargs" , bootargs); -printf ("append: %s\n" , bootargs); +run_command (bootargs,0 ); +printf ("append: %s\n" ,getenv ("bootargs" ));free (bootargs); }
Signature · 1 line
2.0.3
PATCH 1/1 pxe: Allow use of environment variables in append string
Quoted 2 lines · Hans de Goede
Use
run_command("setenv bootargs <label->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..
common/cmd_pxe.c static void label_print(void *data) · line 585
Quoted 12 lines
common/cmd_pxe.c +5
-2if (!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.
common/cmd_pxe.c static void label_print(void *data) · line 588
Quoted 3 lines
common/cmd_pxe.c +3
-0+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.
There would still be the issue of $ suddenly meaning something different.
PATCH 1/1 pxe: Allow use of environment variables in append string
Hi,
Quoted 5 lines · Stephen Warren
Quoted 2 lines · Hans de Goede
Use
run_command("setenv bootargs <label->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...
Quoted 14 lines
common/cmd_pxe.c static void label_print(void *data) · line 585
Quoted 13 lines
common/cmd_pxe.c +5
-2if (!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 ;
Quoted 1 line
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.
Quoted 5 lines
common/cmd_pxe.c static void label_print(void *data) · line 588
Quoted 3 lines
common/cmd_pxe.c +3
-0+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 ; inlabel->appendcausing part oflabel->appendafter the ; to be execututed as a separate command.
Ack, I'll look into that and post a v2 with that change.
Quoted 1 line
There would still be the issue of $ suddenly meaning something different.
Right, but as said I'm not really worried about that.
Regards,
Hans