[syslinux:elflink] elflink: Set PATH to the directory containing ldlinux.c32

syslinux-bot for Matt Fleming matt.fleming at intel.com
Fri Jan 25 03:45:07 PST 2013


Commit-ID:  c250a42263c8717469c8a07d04567ce8333814dd
Gitweb:     http://www.syslinux.org/commit/c250a42263c8717469c8a07d04567ce8333814dd
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Fri, 25 Jan 2013 11:12:52 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 25 Jan 2013 11:19:02 +0000

elflink: Set PATH to the directory containing ldlinux.c32

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 at intel.com>

---
 core/elflink/load_env32.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index 7a6b08f..3ddbfec 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -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");
 }
 


More information about the Syslinux-commits mailing list