elflink: Set PATH to the directory containing ldlinux.c32 syslinux-5.01-pre5
authorMatt Fleming <matt.fleming@intel.com>
Fri, 25 Jan 2013 11:12:52 +0000 (11:12 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Fri, 25 Jan 2013 11:19:02 +0000 (11:19 +0000)
On ISOLINUX and PXELINUX, CurrentDirName doesn't contain anything
useful when we enter load_env32(). commit 10bb72d1528b ("PATH: Use
installation directory for 'PATH'") didn't handle the case where we
don't have an installation path, or don't find ldlinux.c32 there. If
we find ldlinux.c32 in one of 'search_directories' use that directory
as the PATH string.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
core/elflink/load_env32.c

index 7a6b08f..3ddbfec 100644 (file)
@@ -127,7 +127,7 @@ void load_env32(com32sys_t * regs __unused)
        PATH = malloc(strlen(CurrentDirName) + 1);
        if (!PATH) {
                printf("Couldn't allocate memory for PATH\n");
-               return;
+               goto out;
        }
 
        strcpy(PATH, CurrentDirName);
@@ -142,15 +142,36 @@ void load_env32(com32sys_t * regs __unused)
         * a bit harder to find LDLINUX. If search_dirs() succeeds
         * in finding LDLINUX it will set the cwd.
         */
+       free(PATH);
        fd = opendev(&__file_dev, NULL, O_RDONLY);
        if (fd < 0)
                return;
 
        fp = &__file_info[fd];
 
-       if (!search_dirs(&fp->i.fd, search_directories, filenames, realname))
+       if (!search_dirs(&fp->i.fd, search_directories, filenames, realname)) {
+               char path[FILENAME_MAX];
+
+               /*
+                * search_dirs() sets the current working directory if
+                * it successfully opens the file. Set PATH to the
+                * directory in which we found ldlinux.c32.
+                */
+               if (!core_getcwd(path, sizeof(path)))
+                       goto out;
+
+               PATH = malloc(strlen(path) + 1);
+               if (!PATH) {
+                       printf("Couldn't allocate memory for PATH\n");
+                       goto out;
+               }
+
+               strcpy(PATH, path);
+
                start_ldlinux(argv);
+       }
 
+out:
        writestr("\nFailed to load ldlinux.c32");
 }