int command_boot(int argc, char *argv[]) { struct preloaded_file *fp; /* * See if the user has specified an explicit kernel to boot. */ if ((argc > 1) && (argv[1][0] != '-')) { /* XXX maybe we should discard everything and start again? */ if (file_findfile(NULL, NULL) != NULL) { command_seterr("can't boot '%s', kernel module already loaded", argv[1]); return(CMD_ERROR); } /* find/load the kernel module */ if (file_loadkernel(argv[1], argc - 2, argv + 2) != 0) return(CMD_ERROR); /* we have consumed all arguments */ argc = 1; } /* * See if there is a kernel module already loaded */ if (file_findfile(NULL, NULL) == NULL) if (loadakernel(0, argc - 1, argv + 1)) /* we have consumed all arguments */ argc = 1; /* * Loaded anything yet? */ if ((fp = file_findfile(NULL, NULL)) == NULL) { command_seterr("no bootable kernel"); return(CMD_ERROR); } /* * If we were given arguments, discard any previous. * XXX should we merge arguments? Hard to DWIM. */ if (argc > 1) { if (fp->f_args != NULL) free(fp->f_args); fp->f_args = unargv(argc - 1, argv + 1); } /* Hook for platform-specific autoloading of modules */ if (archsw.arch_autoload() != 0) return(CMD_ERROR); /* Call the exec handler from the loader matching the kernel */ command_seterr("%s", strerror(file_formats[fp->f_loader]->l_exec(fp))); return(CMD_ERROR); }
int autoboot(int timeout, char *prompt) { time_t when, otime, ntime; int c, yes; char *argv[2], *cp, *ep; char *kernelname; #ifdef BOOT_PROMPT_123 const char *seq = "123", *p = seq; #endif autoboot_tried = 1; if (timeout == -1) { timeout = 10; /* try to get a delay from the environment */ if ((cp = getenv("autoboot_delay"))) { timeout = strtol(cp, &ep, 0); if (cp == ep) timeout = 10; /* Unparseable? Set default! */ } } 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); } } if (timeout >= 0) { otime = time(NULL); when = otime + timeout; /* when to boot */ yes = 0; #ifdef BOOT_PROMPT_123 printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or " "1 2 3 sequence for command prompt." : prompt); #else printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt); #endif for (;;) { if (ischar()) { c = getchar(); #ifdef BOOT_PROMPT_123 if ((c == '\r') || (c == '\n')) { yes = 1; break; } else if (c != *p++) p = seq; if (*p == 0) break; #else if ((c == '\r') || (c == '\n')) yes = 1; break; #endif } ntime = time(NULL); if (ntime >= when) { yes = 1; break; } if (ntime != otime) { printf("\rBooting [%s] in %d second%s... ", kernelname, (int)(when - ntime), (when-ntime)==1?"":"s"); otime = ntime; } } } else { yes = 1; } if (yes) printf("\rBooting [%s]... ", kernelname); putchar('\n'); if (yes) { argv[0] = "boot"; argv[1] = NULL; return(command_boot(1, argv)); } return(CMD_OK); }
int autoboot(int timeout, char *prompt) { time_t when, otime, ntime; int c, yes; char *argv[2], *cp, *ep; char *kernelname; autoboot_tried = 1; if (timeout == -1) { /* try to get a delay from the environment */ if ((cp = getenv("autoboot_delay"))) { timeout = strtol(cp, &ep, 0); if (cp == ep) timeout = -1; } } if (timeout == -1) /* all else fails */ timeout = 10; kernelname = getenv("kernelname"); if (kernelname == NULL) { argv[0] = NULL; loadakernel(0, 0, argv); kernelname = getenv("kernelname"); if (kernelname == NULL) { command_seterr("no valid kernel found"); return(CMD_ERROR); } } otime = time(NULL); when = otime + timeout; /* when to boot */ yes = 0; printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt); for (;;) { if (ischar()) { c = getchar(); if ((c == '\r') || (c == '\n')) yes = 1; break; } ntime = time(NULL); if (ntime >= when) { yes = 1; break; } if (ntime != otime) { printf("\rBooting [%s] in %d second%s... ", kernelname, (int)(when - ntime), (when-ntime)==1?"":"s"); otime = ntime; } } if (yes) printf("\rBooting [%s]... ", kernelname); putchar('\n'); if (yes) { argv[0] = "boot"; argv[1] = NULL; return(command_boot(1, argv)); } return(CMD_OK); }
static int command_boot(int argc, char *argv[]) { struct preloaded_file *fp; char *local_module_path; char *exported_module_path; /* * See if the user has specified an explicit kernel to boot. */ if ((argc > 1) && (argv[1][0] != '-')) { /* XXX maybe we should discard everything and start again? */ if (file_findfile(NULL, NULL) != NULL) { sprintf(command_errbuf, "can't boot '%s', kernel module already loaded", argv[1]); return(CMD_ERROR); } /* find/load the kernel module */ if (mod_loadkld(argv[1], argc - 2, argv + 2) != 0) return(CMD_ERROR); /* we have consumed all arguments */ argc = 1; } /* * See if there is a kernel module already loaded */ if (file_findfile(NULL, NULL) == NULL) if (loadakernel(0, argc - 1, argv + 1)) /* we have consumed all arguments */ argc = 1; /* * Loaded anything yet? */ if ((fp = file_findfile(NULL, NULL)) == NULL) { command_errmsg = "no bootable kernel"; return(CMD_ERROR); } /* * If we were given arguments, discard any previous. * XXX should we merge arguments? Hard to DWIM. */ if (argc > 1) { if (fp->f_args != NULL) free(fp->f_args); fp->f_args = unargv(argc - 1, argv + 1); } /* Hook for platform-specific autoloading of modules */ if (archsw.arch_autoload() != 0) return(CMD_ERROR); /* * Exec the kernel. We have to shift our exported_module_path * (which has the correct /boot prefix for the kernel) over to * module_path. If the exec fails we switch it back. */ exported_module_path = getenv("exported_module_path"); if (exported_module_path) { exported_module_path = strdup(exported_module_path); local_module_path = getenv("module_path"); if (local_module_path) local_module_path = strdup(local_module_path); setenv("module_path", exported_module_path, 1); unsetenv("exported_module_path"); } /* Call the exec handler from the loader matching the kernel */ file_formats[fp->f_loader]->l_exec(fp); if (exported_module_path) { if (local_module_path) { setenv("module_path", local_module_path, 1); free(local_module_path); } else { unsetenv("module_path"); } setenv("exported_module_path", exported_module_path, 1); free(exported_module_path); } return(CMD_ERROR); }