diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1998-05-25 19:17:44 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1998-05-25 19:17:44 +0000 |
commit | afbd2fd9b7d385cda50f7b241a5ce94cbb2c3255 (patch) | |
tree | a5b866f205e1d5cda3c2982f665f51b0e2f5cd07 /sys/stand/boot | |
parent | 6339bfab7630b50c22400f0f4fcf8b944c9ad61f (diff) |
make a new file for variable manipulation code; add environment support
Diffstat (limited to 'sys/stand/boot')
-rw-r--r-- | sys/stand/boot/boot.c | 4 | ||||
-rw-r--r-- | sys/stand/boot/bootarg.c | 4 | ||||
-rw-r--r-- | sys/stand/boot/bootarg.h | 4 | ||||
-rw-r--r-- | sys/stand/boot/cmd.c | 178 | ||||
-rw-r--r-- | sys/stand/boot/cmd.h | 4 | ||||
-rw-r--r-- | sys/stand/boot/vars.c | 245 |
6 files changed, 260 insertions, 179 deletions
diff --git a/sys/stand/boot/boot.c b/sys/stand/boot/boot.c index 0cb73a4b5f7..48b63e774c5 100644 --- a/sys/stand/boot/boot.c +++ b/sys/stand/boot/boot.c @@ -1,7 +1,7 @@ -/* $OpenBSD: boot.c,v 1.18 1998/05/14 14:39:11 mickey Exp $ */ +/* $OpenBSD: boot.c,v 1.19 1998/05/25 19:17:36 mickey Exp $ */ /* - * Copyright (c) 1997 Michael Shalayeff + * Copyright (c) 1997,1998 Michael Shalayeff * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/stand/boot/bootarg.c b/sys/stand/boot/bootarg.c index efee8f52cc4..72f803a8804 100644 --- a/sys/stand/boot/bootarg.c +++ b/sys/stand/boot/bootarg.c @@ -1,7 +1,7 @@ -/* $OpenBSD: bootarg.c,v 1.4 1998/04/18 07:40:02 deraadt Exp $ */ +/* $OpenBSD: bootarg.c,v 1.5 1998/05/25 19:17:38 mickey Exp $ */ /* - * Copyright (c) 1997 Michael Shalayeff + * Copyright (c) 1997,1998 Michael Shalayeff * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/stand/boot/bootarg.h b/sys/stand/boot/bootarg.h index 36f931afc02..cb622987190 100644 --- a/sys/stand/boot/bootarg.h +++ b/sys/stand/boot/bootarg.h @@ -1,7 +1,7 @@ -/* $OpenBSD: bootarg.h,v 1.4 1998/05/18 21:51:45 mickey Exp $ */ +/* $OpenBSD: bootarg.h,v 1.5 1998/05/25 19:17:39 mickey Exp $ */ /* - * Copyright (c) 1996,1997,1998 Michael Shalayeff + * Copyright (c) 1996-1998 Michael Shalayeff * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/stand/boot/cmd.c b/sys/stand/boot/cmd.c index df77cb88510..b2bc36cc022 100644 --- a/sys/stand/boot/cmd.c +++ b/sys/stand/boot/cmd.c @@ -1,7 +1,7 @@ -/* $OpenBSD: cmd.c,v 1.37 1998/04/18 07:40:03 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.38 1998/05/25 19:17:40 mickey Exp $ */ /* - * Copyright (c) 1997 Michael Shalayeff + * Copyright (c) 1997,1998 Michael Shalayeff * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,48 +37,29 @@ #include <sys/reboot.h> #include "cmd.h" -extern int debug; - #define CTRL(c) ((c)&0x1f) -static int Xaddr __P((void)); static int Xboot __P((void)); -static int Xdevice __P((void)); -#ifdef DEBUG -static int Xdebug __P((void)); -#endif +static int Xecho __P((void)); static int Xhelp __P((void)); -static int Ximage __P((void)); static int Xls __P((void)); static int Xnop __P((void)); static int Xreboot __P((void)); -static int Xset __P((void)); static int Xstty __P((void)); -static int Xhowto __P((void)); -static int Xtty __P((void)); static int Xtime __P((void)); -static int Xecho __P((void)); #ifdef MACHINE_CMD static int Xmachine __P((void)); extern const struct cmd_table MACHINE_CMD[]; #endif +extern int Xset __P((void)); +extern int Xenv __P((void)); -const struct cmd_table cmd_set[] = { - {"addr", CMDT_VAR, Xaddr}, - {"howto", CMDT_VAR, Xhowto}, -#ifdef DEBUG - {"debug", CMDT_VAR, Xdebug}, -#endif - {"device", CMDT_VAR, Xdevice}, - {"tty", CMDT_VAR, Xtty}, - {"image", CMDT_VAR, Ximage}, - {NULL,0} -}; - +extern const struct cmd_table cmd_set[]; const struct cmd_table cmd_table[] = { {"#", CMDT_CMD, Xnop}, /* XXX must be first */ {"boot", CMDT_CMD, Xboot}, {"echo", CMDT_CMD, Xecho}, + {"env", CMDT_CMD, Xenv}, {"help", CMDT_CMD, Xhelp}, {"ls", CMDT_CMD, Xls}, #ifdef MACHINE_CMD @@ -91,11 +72,9 @@ const struct cmd_table cmd_table[] = { {NULL, 0}, }; -extern const char version[]; static void ls __P((char *, register struct stat *)); static int readline __P((register char *, int)); char *nextword __P((register char *)); -static int bootparse __P((int)); static char *whatcmd __P((register const struct cmd_table **ct, register char *)); static int docmd __P((void)); @@ -307,20 +286,6 @@ nextword(p) return p; } -#ifdef DEBUG -static int -Xdebug() -{ - if (cmd.argc !=2) - printf(debug? "on": "off"); - else - debug = (cmd.argv[1][0] == '0' || - (cmd.argv[1][0] == 'o' && cmd.argv[1][1] == 'f'))? - 0: 1; - return 0; -} -#endif - static void print_help(register const struct cmd_table *ct) { @@ -361,21 +326,6 @@ Xecho() return 0; } -/* called only w/ no arguments */ -static int -Xset() -{ - register const struct cmd_table *ct; - - printf("OpenBSD boot[%s]\n", version); - for (ct = cmd_set; ct->cmd_name != NULL; ct++) { - printf("%s\t ", ct->cmd_name); - (*ct->cmd_exec)(); - putchar('\n'); - } - return 0; -} - static int Xstty() { @@ -406,57 +356,6 @@ Xstty() } static int -Xdevice() -{ - if (cmd.argc != 2) - printf(cmd.bootdev); - else - strncpy(cmd.bootdev, cmd.argv[1], sizeof(cmd.bootdev)); - return 0; -} - -static int -Ximage() -{ - if (cmd.argc != 2) - printf(cmd.image); - else - strncpy(cmd.image, cmd.argv[1], sizeof(cmd.image)); - return 0; -} - -static int -Xaddr() -{ - if (cmd.argc != 2) - printf("%p", cmd.addr); - else - cmd.addr = (void *)strtol(cmd.argv[1], NULL, 0); - return 0; -} - -static int -Xtty() -{ - dev_t dev; - - if (cmd.argc == 1) - printf(ttyname(0)); - else { - dev = ttydev(cmd.argv[1]); - if (dev == NODEV) - printf("%s not a console device\n", cmd.argv[1]); - else { - printf("switching console to %s\n", cmd.argv[1]); - if (cnset(dev)) - printf("%s console not present\n", - cmd.argv[1]); - } - } - return 0; -} - -static int Xtime() { if (cmd.argc == 1) @@ -539,28 +438,6 @@ Xnop() } static int -Xhowto() -{ - if (cmd.argc < 2) { - if (cmd.boothowto) { - putchar('-'); - if (cmd.boothowto & RB_ASKNAME) - putchar('a'); - if (cmd.boothowto & RB_HALT) - putchar('b'); - if (cmd.boothowto & RB_CONFIG) - putchar('c'); - if (cmd.boothowto & RB_SINGLE) - putchar('s'); - if (cmd.boothowto & RB_KDB) - putchar('d'); - } - } else - bootparse(1); - return 0; -} - -static int Xboot() { if (cmd.argc > 1 && cmd.argv[1][0] != '-') { @@ -597,47 +474,6 @@ qualify(name) } static int -bootparse(i) - int i; -{ - register char *cp; - int howto = cmd.boothowto; - - for (; i < cmd.argc; i++) { - cp = cmd.argv[i]; - if (*cp == '-') { - while (*++cp) { - switch (*cp) { - case 'a': - howto |= RB_ASKNAME; - break; - case 'b': - howto |= RB_HALT; - break; - case 'c': - howto |= RB_CONFIG; - break; - case 's': - howto |= RB_SINGLE; - break; - case 'd': - howto |= RB_KDB; - break; - default: - printf("howto: bad option: %c\n", *cp); - return 1; - } - } - } else { - printf("boot: illegal argument %s\n", cmd.argv[i]); - return 1; - } - } - cmd.boothowto = howto; - return 0; -} - -static int Xreboot() { printf("Rebooting...\n"); diff --git a/sys/stand/boot/cmd.h b/sys/stand/boot/cmd.h index a3ecfcad048..fdac86cc1fe 100644 --- a/sys/stand/boot/cmd.h +++ b/sys/stand/boot/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.9 1997/09/02 20:48:18 mickey Exp $ */ +/* $OpenBSD: cmd.h,v 1.10 1998/05/25 19:17:42 mickey Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -60,4 +60,4 @@ extern struct cmd_state cmd; int getcmd __P((void)); int read_conf __P((void)); - +int bootparse __P((int)); diff --git a/sys/stand/boot/vars.c b/sys/stand/boot/vars.c new file mode 100644 index 00000000000..644e27b11dc --- /dev/null +++ b/sys/stand/boot/vars.c @@ -0,0 +1,245 @@ +/* $OpenBSD: vars.c,v 1.1 1998/05/25 19:17:43 mickey Exp $ */ + +/* + * Copyright (c) 1998 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Michael Shalayeff. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <sys/param.h> +#include <libsa.h> +#include <sys/reboot.h> +#include "cmd.h" + +extern const char version[]; +extern int debug; + +static int Xaddr __P((void)); +static int Xdevice __P((void)); +#ifdef DEBUG +static int Xdebug __P((void)); +#endif +static int Ximage __P((void)); +static int Xhowto __P((void)); +static int Xtty __P((void)); +int Xset __P((void)); +int Xenv __P((void)); + +const struct cmd_table cmd_set[] = { + {"addr", CMDT_VAR, Xaddr}, + {"howto", CMDT_VAR, Xhowto}, +#ifdef DEBUG + {"debug", CMDT_VAR, Xdebug}, +#endif + {"device", CMDT_VAR, Xdevice}, + {"tty", CMDT_VAR, Xtty}, + {"image", CMDT_VAR, Ximage}, + {NULL,0} +}; + +#ifdef DEBUG +static int +Xdebug() +{ + if (cmd.argc !=2) + printf(debug? "on": "off"); + else + debug = (cmd.argv[1][0] == '0' || + (cmd.argv[1][0] == 'o' && cmd.argv[1][1] == 'f'))? + 0: 1; + return 0; +} +#endif + +/* called only w/ no arguments */ +int +Xset() +{ + register const struct cmd_table *ct; + + printf(">> OpenBSD/" MACHINE_ARCH " BOOT %s\n", version); + for (ct = cmd_set; ct->cmd_name != NULL; ct++) { + printf("%s\t ", ct->cmd_name); + (*ct->cmd_exec)(); + putchar('\n'); + } + return 0; +} + +static int +Xdevice() +{ + if (cmd.argc != 2) + printf(cmd.bootdev); + else + strncpy(cmd.bootdev, cmd.argv[1], sizeof(cmd.bootdev)); + return 0; +} + +static int +Ximage() +{ + if (cmd.argc != 2) + printf(cmd.image); + else + strncpy(cmd.image, cmd.argv[1], sizeof(cmd.image)); + return 0; +} + +static int +Xaddr() +{ + if (cmd.argc != 2) + printf("%p", cmd.addr); + else + cmd.addr = (void *)strtol(cmd.argv[1], NULL, 0); + return 0; +} + +static int +Xtty() +{ + dev_t dev; + + if (cmd.argc != 2) + printf(ttyname(0)); + else { + dev = ttydev(cmd.argv[1]); + if (dev == NODEV) + printf("%s not a console device\n", cmd.argv[1]); + else { + printf("switching console to %s\n", cmd.argv[1]); + if (cnset(dev)) + printf("%s console not present\n", + cmd.argv[1]); + } + } + return 0; +} + +static int +Xhowto() +{ + if (cmd.argc == 1) { + if (cmd.boothowto) { + putchar('-'); + if (cmd.boothowto & RB_ASKNAME) + putchar('a'); + if (cmd.boothowto & RB_HALT) + putchar('b'); + if (cmd.boothowto & RB_CONFIG) + putchar('c'); + if (cmd.boothowto & RB_SINGLE) + putchar('s'); + if (cmd.boothowto & RB_KDB) + putchar('d'); + } + } else + bootparse(1); + return 0; +} + +int +bootparse(i) + int i; +{ + register char *cp; + int howto = cmd.boothowto; + + for (; i < cmd.argc; i++) { + cp = cmd.argv[i]; + if (*cp == '-') { + while (*++cp) { + switch (*cp) { + case 'a': + howto |= RB_ASKNAME; + break; + case 'b': + howto |= RB_HALT; + break; + case 'c': + howto |= RB_CONFIG; + break; + case 's': + howto |= RB_SINGLE; + break; + case 'd': + howto |= RB_KDB; + break; + default: + printf("howto: bad option: %c\n", *cp); + return 1; + } + } + } else { + printf("boot: illegal argument %s\n", cmd.argv[i]); + return 1; + } + } + cmd.boothowto = howto; + return 0; +} + +/* + * maintain environmanet as a sequence of '\n' separated + * variable definitions in the form <name>=[<value>] + * terminated by the usual '\0' + */ +char *environ; +int +Xenv() +{ + if (cmd.argc == 1) { + if (environ) + printf(environ); + else + printf("empty\n"); + } else { + register char *p, *q; + int l; + for (p = environ; p && *p; p = q) { + l = strlen(cmd.argv[1]); + for (q = p; *q != '='; q++); + l = max(l, q - p); + for (q = p; *q != '\n'; q++); + if (*q) + q++; + if (!strncmp(p, cmd.argv[1], l)) { + while((*p++ = *q++)); + p--; + } + } + if (!p) + p = environ = alloc(NBPG); + sprintf(p, "%s=%s\n", + cmd.argv[1], (cmd.argc==3?cmd.argv[2]:"")); + } + + return 0; +} |