diff options
author | dcs <dcs@FreeBSD.org> | 2000-09-08 16:47:05 +0000 |
---|---|---|
committer | dcs <dcs@FreeBSD.org> | 2000-09-08 16:47:05 +0000 |
commit | 475f83c70ca2a39eacdb9dfe774681a8e8c2f305 (patch) | |
tree | 4bb815da23b865dd3501a646531853dae61d312e /sys/boot | |
parent | 9310f79758721695fb2fd0b07e7ea673b30f857b (diff) | |
download | FreeBSD-src-475f83c70ca2a39eacdb9dfe774681a8e8c2f305.zip FreeBSD-src-475f83c70ca2a39eacdb9dfe774681a8e8c2f305.tar.gz |
Fix autoboot. Now autoboot *always* show the correct kernel name. It
gets the name from the environment variable kernelname, which is set
when a kernel is loaded. For this reason, autoboot will _first_ try
to load a kernel, and only proceed with the wait prompt after that
succeeds. If it fails, it will abort immediately.
While I understand some may think this behavior undesirable, I think
it is, overall, the best thing to do, even if we do not consider the
aesthetic issue. Notice that anyone using the default loader.rc
already has the kernel loaded before autoboot.
On unload, unset kernelname.
Separate the code that tries to load a kernel from the list of options
to the function loadakernel(). It is used by both boot() and
autoboot().
Diffstat (limited to 'sys/boot')
-rw-r--r-- | sys/boot/common/boot.c | 53 | ||||
-rw-r--r-- | sys/boot/common/module.c | 1 |
2 files changed, 37 insertions, 17 deletions
diff --git a/sys/boot/common/boot.c b/sys/boot/common/boot.c index 3913e34..70b1fb1 100644 --- a/sys/boot/common/boot.c +++ b/sys/boot/common/boot.c @@ -36,6 +36,7 @@ #include "bootstrap.h" static char *getbootfile(int try); +static int loadakernel(int try, int argc, char* argv[]); /* List of kernel names to try (may be overwritten by boot.config) XXX should move from here? */ static const char *default_bootfiles = "kernel.ko"; @@ -51,8 +52,6 @@ static int command_boot(int argc, char *argv[]) { struct preloaded_file *fp; - char *cp; - int try; /* * See if the user has specified an explicit kernel to boot. @@ -75,17 +74,10 @@ command_boot(int argc, char *argv[]) /* * See if there is a kernel module already loaded */ - if (file_findfile(NULL, NULL) == NULL) { - for (try = 0; (cp = getbootfile(try)) != NULL; try++) { - if (mod_load(cp, argc - 1, argv + 1) != 0) { - printf("can't load '%s'\n", cp); - } else { - /* we have consumed all arguments */ - argc = 1; - break; - } - } - } + if (file_findfile(NULL, NULL) == NULL) + if (loadakernel(0, argc - 1, argv + 1)) + /* we have consumed all arguments */ + argc = 1; /* * Loaded anything yet? @@ -168,6 +160,7 @@ autoboot(int timeout, char *prompt) time_t when, otime, ntime; int c, yes; char *argv[2], *cp, *ep; + char *kernelname; autoboot_tried = 1; @@ -186,7 +179,17 @@ autoboot(int timeout, char *prompt) when = otime + timeout; /* when to boot */ yes = 0; - /* XXX could try to work out what we might boot */ + kernelname = getenv("kernelname"); + if (kernelname == NULL) { + argv[0] = NULL; + loadakernel(0, 0, argv); + kernelname = getenv("kernelname"); + if (kernelname == NULL) { + command_errmsg = "no valid kernel found"; + return(CMD_ERROR); + } + } + printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt); for (;;) { @@ -201,15 +204,16 @@ autoboot(int timeout, char *prompt) yes = 1; break; } + if (ntime != otime) { printf("\rBooting [%s] in %d second%s... ", - getbootfile(0), (int)(when - ntime), + kernelname, (int)(when - ntime), (when-ntime)==1?"":"s"); otime = ntime; } } if (yes) - printf("\rBooting [%s]... ", getbootfile(0)); + printf("\rBooting [%s]... ", kernelname); putchar('\n'); if (yes) { argv[0] = "boot"; @@ -226,7 +230,7 @@ static char * getbootfile(int try) { static char *name = NULL; - char *spec, *ep; + const char *spec, *ep; size_t len; /* we use dynamic storage */ @@ -332,3 +336,18 @@ getrootmount(char *rootdev) close(fd); return(error); } + +static int +loadakernel(int try, int argc, char* argv[]) +{ + char *cp; + + for (try = 0; (cp = getbootfile(try)) != NULL; try++) + if (mod_load(cp, argc - 1, argv + 1) != 0) + printf("can't load '%s'\n", cp); + else + return 1; + + return 0; +} + diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c index 192e58d..4f4be9c 100644 --- a/sys/boot/common/module.c +++ b/sys/boot/common/module.c @@ -129,6 +129,7 @@ command_unload(int argc, char *argv[]) file_discard(fp); } loadaddr = 0; + unsetenv("kernelname"); return(CMD_OK); } |