ldlinux: Pass entire cmdline to execute()
authorMatt Fleming <matt.fleming@linux.intel.com>
Fri, 8 Apr 2011 12:15:43 +0000 (13:15 +0100)
committerMatt Fleming <matt.fleming@linux.intel.com>
Sat, 16 Apr 2011 13:49:26 +0000 (14:49 +0100)
We need to pass the entire cmdline to execute(), not just the kernel
name. execute() does all the required processing of cmdline arguments
and passes them to the loader in the correct format, e.g. for COM32
modules the cmdline arguments need to be passed in the traditional
char *argv[] way.

So stop using strtok() which modifies its first argument and means we
therefore lose the cmdline after the kernel name.

Previously, the "argc" and "argv" arguments that are passed to a
module's main() function contained bogus values.

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
com32/elflink/ldlinux/ldlinux.c

index 36eaded..839a28a 100644 (file)
@@ -22,8 +22,7 @@ static void load_kernel(const char *kernel)
 {
        struct menu_entry *me;
        enum kernel_type type;
-       const char *cmdline;
-       char *kernel_name;
+       const char *cmdline, *p;
        int len;
 
        /* Virtual kernel? */
@@ -38,23 +37,25 @@ static void load_kernel(const char *kernel)
        if (!allowimplicit)
                goto bad_implicit;
 
-       kernel_name = strtok((char *)kernel, COMMAND_DELIM);
-       len = strlen(kernel_name);
+       /* Find the end of the command */
+       while (*p && !my_isspace(*p))
+               p++;
 
-       if (!strcmp(kernel_name + len - 4, ".c32")) {
+       len = p - kernel;
+       if (!strncmp(kernel + len - 4, ".c32", 4)) {
                type = KT_COM32;
-       } else if (!strcmp(kernel_name + len - 2, ".0")) {
+       } else if (!strncmp(kernel + len - 2, ".0", 2)) {
                type = KT_PXE;
-       } else if (!strcmp(kernel_name + len - 3, ".bs")) {
+       } else if (!strncmp(kernel + len - 3, ".bs", 3)) {
                type = KT_BOOT;
-       } else if (!strcmp(kernel_name + len - 4, ".img")) {
+       } else if (!strncmp(kernel + len - 4, ".img", 4)) {
                type = KT_FDIMAGE;
-       } else if (!strcmp(kernel_name + len - 4, ".bin")) {
+       } else if (!strncmp(kernel + len - 4, ".bin", 4)) {
                type = KT_BOOT;
-       } else if (!strcmp(kernel_name + len - 4, ".bss")) {
+       } else if (!strncmp(kernel + len - 4, ".bss", 4)) {
                type = KT_BSS;
-       } else if (!strcmp(kernel_name + len - 4, ".com")
-              || !strcmp(kernel_name + len - 4, ".cbt")) {
+       } else if (!strncmp(kernel + len - 4, ".com", 4) ||
+                  !strncmp(kernel + len - 4, ".cbt", 4)) {
                type = KT_COMBOOT;
        }
        /* use KT_KERNEL as default */