1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

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().
This commit is contained in:
Daniel C. Sobral 2000-09-08 16:47:05 +00:00
parent 0c8c2cd619
commit 59549c5031
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=65613
2 changed files with 37 additions and 17 deletions

View File

@ -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;
}

View File

@ -129,6 +129,7 @@ command_unload(int argc, char *argv[])
file_discard(fp);
}
loadaddr = 0;
unsetenv("kernelname");
return(CMD_OK);
}