Exemple #1
0
void
getbootdev(int *howto)
{
	char c, *ptr = line;

	printf("Boot: [[[%s%d%c:]%s][-acds]] :- ",
	    devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name);

	if (tgets(line)) {
		if (strcmp(line, "reset") == 0) {
			call_req_reboot();      /* reset machine */
			printf("panic: can't reboot, halting\n");
			asm("stop #0x2700");
		}
		while ((c = *ptr) != '\0') {
			while (c == ' ')
				c = *++ptr;
			if (!c)
				return;
			if (c == '-')
				while ((c = *++ptr) && c != ' ')
					switch (c) {
					case 'a':
						*howto |= RB_ASKNAME;
						continue;
					case 'b':
						*howto |= RB_HALT;
						continue;
					case 'c':
						*howto |= RB_CONFIG;
						continue;
					case 'd':
						*howto |= RB_KDB;
						continue;
					case 's':
						*howto |= RB_SINGLE;
						continue;
					}
			else {
				name = ptr;
				while ((c = *++ptr) && c != ' ');
				if (c)
					*ptr++ = 0;
			}
		}
	} else
		printf("\n");
}
/*
 * Extract NetBSD boot specification
 */
static int
get_bsdbootname(char **dev, char **kname, int *howtop)
{
	int len;
	int bootunit, bootpart;
	char *bootstr_dev, *bootstr_kname;
	char *prompt_dev, *prompt_kname;
	char *ptr, *spec;
	char c, namebuf[PATH_MAX];
	static char bootdev[] = "wd0a";
	static char nfsbootdev[] = "nfs";

	bootstr_dev = prompt_dev = NULL;
	bootstr_kname = prompt_kname = NULL;

	/* first, get root device specified by the firmware */
	spec = bootstring;

	/* assume the last one is valid */
	while ((spec = strstr(spec, "root=")) != NULL) {
		spec += 5;	/* skip 'root=' */
		ptr = strchr(spec, ' ');
		len = (ptr == NULL) ? strlen(spec) : ptr - spec;
		/* decode unit and part from "/dev/hd[ab][1-4]" strings */
		if (len == 9 && memcmp("/dev/hd", spec, 7) == 0) {
			bootunit = spec[7] - 'a';
			bootpart = spec[8] - '1';
			if (bootunit >= 0 && bootunit < 2 &&
			    bootpart >= 0 && bootpart < 4) {
				bootdev[sizeof(bootdev) - 3] = '0' + bootunit;
#if 0				/* bootpart is fdisk partition of Linux root */
				bootdev[sizeof(bootdev) - 2] = 'a' + bootpart;
#endif
				bootstr_dev = bootdev;
			}
		}
		spec += len;
	}

	/* second, get bootname from bootstrings */
	if ((spec = strstr(bootstring, "nbsd=")) != NULL) {
		ptr = strchr(spec, ' ');
		spec += 5; 	/* skip 'nbsd=' */
		len = (ptr == NULL) ? strlen(spec) : ptr - spec;
		if (len > 0) {
			if (parse_bootname(spec, len,
			    &bootstr_dev, &bootstr_kname))
				return 1;
		}
	}

	/* third, check if netboot */
	if (strstr(bootstring, "nfsroot=") != NULL) {
		bootstr_dev = nfsbootdev;
	}

	DPRINTF(("bootstr_dev = %s, bootstr_kname = %s\n",
	    bootstr_dev ? bootstr_dev : "<NULL>",
	    bootstr_kname ? bootstr_kname : "<NULL>"));

	spec = NULL;
	len = 0;

	memset(namebuf, 0, sizeof namebuf);
	printf("Boot [%s:%s]: ",
	    bootstr_dev ? bootstr_dev : DEFBOOTDEV,
	    bootstr_kname ? bootstr_kname : DEFKERNELNAME);

	if (tgets(namebuf) == -1)
		printf("\n");

	ptr = namebuf;
	while ((c = *ptr) != '\0') {
		while (c == ' ')
			c = *++ptr;
		if (c == '\0')
			break;
		if (c == '-') {
			while ((c = *++ptr) && c != ' ')
				BOOT_FLAG(c, *howtop);
		} else {
			spec = ptr;
			while ((c = *++ptr) && c != ' ')
				;
			if (c)
				*ptr++ = '\0';
			len = strlen(spec);
		}
	}

	if (len > 0) {
		if (parse_bootname(spec, len, &prompt_dev, &prompt_kname))
			return 1;
	}

	DPRINTF(("prompt_dev = %s, prompt_kname = %s\n",
	    prompt_dev ? prompt_dev : "<NULL>",
	    prompt_kname ? prompt_kname : "<NULL>"));

	if (prompt_dev)
		*dev = prompt_dev;
	else
		*dev = bootstr_dev;

	if (prompt_kname)
		*kname = prompt_kname;
	else
		*kname = bootstr_kname;

	DPRINTF(("dev = %s, kname = %s\n",
	    *dev ? *dev : "<NULL>",
	    *kname ? *kname : "<NULL>"));

	return 0;
}
Exemple #3
0
/*
 *  popper: Handle a Post Office Protocol version 3 session
 */
int
main (int argc, char **argv)
{
    POP                 p;
    state_table     *   s;
    char                message[MAXLINELEN];

    signal(SIGHUP,  catchSIGHUP);
    signal(SIGPIPE, catchSIGHUP);

    /*  Start things rolling */
    pop_init(&p,argc,argv);

    /*  Tell the user that we are listenting */
    pop_msg(&p,POP_SUCCESS, "POP3 server ready");

    /*  State loop.  The POP server is always in a particular state in
        which a specific suite of commands can be executed.  The following
        loop reads a line from the client, gets the command, and processes
        it in the current context (if allowed) or rejects it.  This continues
        until the client quits or an error occurs. */

    for (p.CurrentState=auth1;p.CurrentState!=halt&&p.CurrentState!=error;) {
        if (hangup) {
            pop_msg(&p, POP_FAILURE, "POP hangup: %s", p.myhost);
            if (p.CurrentState > auth2 && !pop_updt(&p))
                pop_msg(&p, POP_FAILURE,
			"POP mailbox update failed: %s", p.myhost);
            p.CurrentState = error;
        } else if (tgets(message, MAXLINELEN, p.input, pop_timeout) == NULL) {
	    pop_msg(&p, POP_FAILURE, "POP timeout: %s", p.myhost);
	    if (p.CurrentState > auth2 && !pop_updt(&p))
                pop_msg(&p,POP_FAILURE,
			"POP mailbox update failed: %s", p.myhost);
            p.CurrentState = error;
        }
        else {
            /*  Search for the command in the command/state table */
            if ((s = pop_get_command(&p,message)) == NULL) continue;

            /*  Call the function associated with this command in
                the current state */
            if (s->function) p.CurrentState = s->result[(*s->function)(&p)];

            /*  Otherwise assume NOOP and send an OK message to the client */
            else {
                p.CurrentState = s->success_state;
                pop_msg(&p,POP_SUCCESS,"time passes");
            }
        }
    }

    /*  Say goodbye to the client */
    pop_msg(&p,POP_SUCCESS,"Pop server at %s signing off.",p.myhost);

    /*  Log the end of activity */
    pop_log(&p,POP_PRIORITY,
        "(v%s) Ending request from \"%s\" at %s\n",VERSION,p.client,p.ipaddr);

    /*  Stop logging */
    closelog();

    return(0);
}