[ipxe-devel] [PATCH] fix up command-line support

Dave Hansen dave at sr71.net
Tue Jun 28 01:05:34 UTC 2011


I recently upgraded my version of iPXE and I noticed that the
command-line support was no longer working for me.

My command-line looks like:

	BOOT_IMAGE=/boot/ipxe.lkrn && set foo bar && ...

Other folks have it show up like this:

	&& set foo bar && ... BOOT_IMAGE=/boot/ipxe.lkrn

The existing code simply nulls out the first byte of the
BOOT_IMAGE= string:

	if ( ( tmp = strstr ( cmdline, "BOOT_IMAGE=" ) ) != NULL )
		*tmp = '\0';

But, for the case where the command-line _starts_ with
BOOT_IMAGE, this ends up effectively erasing it since
strstr() returns the beginning of the matched string.

This patch should handle both cases.  When "BOOT_IMAGE="
is at the beginning, it moves the cmdline up past the
first space.  When it shows up at the end, it retains the
existing behavior and puts in a NULL character in at the
beginning of "BOOT_IMAGE=".
---
 src/arch/i386/core/cmdline.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/arch/i386/core/cmdline.c b/src/arch/i386/core/cmdline.c
index fa5adb8..be04838 100644
--- a/src/arch/i386/core/cmdline.c
+++ b/src/arch/i386/core/cmdline.c
@@ -92,8 +92,19 @@ static void cmdline_init ( void ) {
 	while ( isspace ( *cmdline ) )
 		cmdline++;
 	if ( ( tmp = strstr ( cmdline, "BOOT_IMAGE=" ) ) != NULL ) {
-		DBGC ( image, "CMDLINE stripping \"%s\"\n", tmp );
-		*tmp = '\0';
+		/* The string seems to happen either at the beginning or
+		 * the end of the command-line.  Handle both. */
+		if ( tmp == cmdline ) {
+			tmp = strstr ( cmdline, " " );
+			if ( tmp != NULL ) {
+				*tmp = '\0';
+			}
+			DBGC ( image, "CMDLINE stripping \"%s \"\n", cmdline );
+			cmdline = tmp + 1;
+		} else {
+			DBGC ( image, "CMDLINE stripping \"%s\"\n", tmp );
+			*tmp = '\0';
+		}
 	}
 	DBGC ( image, "CMDLINE using \"%s\"\n", cmdline );
 
-- 
1.6.6.rc0.50.gaf06e9




More information about the ipxe-devel mailing list