Example #1
0
int
main(void)
{
	char	c;

	init_devices();

	comcninit();

	opt_subcmd_read(NULL);

	print_banner();

	c = awaitkey();
	if (c != '\r' && c != '\n' && c != '\0') {
		printf("type \"?\" or \"h\" for help.\n");
		bootmenu(); /* does not return */
	}

	command_boot(NULL);
	/*
	 * command_boot() returns only if it failed to boot.
	 * we enter to boot menu in this case.
	 */
	bootmenu();
	
	return 0;
}
Example #2
0
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);
}