ldlinux: Don't try reloading ldlinux.c32 unless it's likely to succeed
authorMatt Fleming <matt.fleming@intel.com>
Thu, 29 Nov 2012 22:52:42 +0000 (22:52 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Fri, 30 Nov 2012 11:04:23 +0000 (11:04 +0000)
If we can't access ldlinux.c32 with findpath(), reloading it isn't
going to work so don't unload it or any of the other modules. Instead
return control to the caller.

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

index 2f0e037..4b4faf8 100644 (file)
@@ -126,6 +126,7 @@ void execute(const char *cmdline, uint32_t type)
                ldlinux_enter_command();
        } else if (type == IMAGE_TYPE_CONFIG) {
                char *argv[] = { "ldlinux.c32", NULL };
+               int rv;
 
                /* kernel contains the config file name */
                realpath(ConfigName, kernel, FILENAME_MAX);
@@ -134,7 +135,8 @@ void execute(const char *cmdline, uint32_t type)
                if (*args)
                        mangle_name(config_cwd, args);
 
-               start_ldlinux(argv);
+               rv = start_ldlinux(argv);
+               printf("Failed to exec ldlinux.c32: %s\n", strerror(rv));
        } else if (type == IMAGE_TYPE_LOCALBOOT) {
                local_boot(strtoul(kernel, NULL, 0));
        } else if (type == IMAGE_TYPE_PXE || type == IMAGE_TYPE_BSS ||
index 23d6baa..a4bee75 100644 (file)
@@ -71,9 +71,19 @@ again:
                 * unload all the modules loaded since ldlinux.c32,
                 * and restart initialisation. This is especially
                 * important for config files.
+                *
+                * But before we do that, try our best to make sure
+                * that spawn_load() is gonna succeed, e.g. that we
+                * can find LDLINUX it in PATH.
                 */
                struct elf_module *ldlinux;
+               FILE *f;
+
+               f = findpath(LDLINUX);
+               if (!f)
+                       return ENOENT;
 
+               fclose(f);
                ldlinux = unload_modules_since(LDLINUX);
 
                /*