diff options
author | neel <neel@FreeBSD.org> | 2012-11-06 21:36:37 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2012-11-06 21:36:37 +0000 |
commit | 9aedd7f40e1c87465278d0d58352d48b5b420aa4 (patch) | |
tree | d68632c1d4ea6ccee5fb9320f87b9941a4bff78c | |
parent | 091578815ab0408c9aa2133e259263351101a008 (diff) | |
download | FreeBSD-src-9aedd7f40e1c87465278d0d58352d48b5b420aa4.zip FreeBSD-src-9aedd7f40e1c87465278d0d58352d48b5b420aa4.tar.gz |
Add a callback function to userboot.so to fetch a list of environment
variables and pass them to the kernel.
Bump up the userboot version to USERBOOT_VERSION_3. This takes into account
the bump to USERBOOT_VERSION_2 that has already happened in head (but not
propagated to this branch yet).
Reviewed by: dfr@
Obtained from: NetApp
-rw-r--r-- | sys/boot/userboot/test/test.c | 16 | ||||
-rw-r--r-- | sys/boot/userboot/userboot.h | 14 | ||||
-rw-r--r-- | sys/boot/userboot/userboot/main.c | 14 |
3 files changed, 41 insertions, 3 deletions
diff --git a/sys/boot/userboot/test/test.c b/sys/boot/userboot/test/test.c index a752a80..424520e 100644 --- a/sys/boot/userboot/test/test.c +++ b/sys/boot/userboot/test/test.c @@ -339,6 +339,18 @@ test_getmem(void *arg, uint64_t *lowmem, uint64_t *highmem) *highmem = 0; } +const char * +test_getenv(void *arg, int idx) +{ + static const char *vars[] = { + "foo=bar", + "bar=barbar", + NULL + }; + + return (vars[idx]); +} + struct loader_callbacks_v1 cb = { .putc = test_putc, .getc = test_getc, @@ -365,6 +377,8 @@ struct loader_callbacks_v1 cb = { .delay = test_delay, .exit = test_exit, .getmem = test_getmem, + + .getenv = test_getenv, }; void @@ -424,5 +438,5 @@ main(int argc, char** argv) term.c_lflag &= ~(ICANON|ECHO); tcsetattr(0, TCSAFLUSH, &term); - func(&cb, NULL, USERBOOT_VERSION_1, disk_fd >= 0); + func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0); } diff --git a/sys/boot/userboot/userboot.h b/sys/boot/userboot/userboot.h index 7d8263e..898b9bc 100644 --- a/sys/boot/userboot/userboot.h +++ b/sys/boot/userboot/userboot.h @@ -29,7 +29,7 @@ /* * USERBOOT interface versions */ -#define USERBOOT_VERSION_1 1 +#define USERBOOT_VERSION_3 3 /* * Exit codes from the loader @@ -175,4 +175,16 @@ struct loader_callbacks_v1 { */ void (*getmem)(void *arg, uint64_t *lowmem, uint64_t *highmem); + + /* + * Returns an environment variable in the form "name=value". + * + * If there are no more variables that need to be set in the + * loader environment then return NULL. + * + * 'num' is used as a handle for the callback to identify which + * environment variable to return next. It will begin at 0 and + * each invocation will add 1 to the previous value of 'num'. + */ + const char * (*getenv)(void *arg, int num); }; diff --git a/sys/boot/userboot/userboot/main.c b/sys/boot/userboot/userboot/main.c index 8a8a7d6..0971e1c 100644 --- a/sys/boot/userboot/userboot/main.c +++ b/sys/boot/userboot/userboot/main.c @@ -68,9 +68,10 @@ void loader_main(struct loader_callbacks_v1 *cb, void *arg, int version, int ndisks) { static char malloc[1024*1024]; + const char *var; int i; - if (version != USERBOOT_VERSION_1) + if (version != USERBOOT_VERSION_3) abort(); callbacks = cb; @@ -105,6 +106,17 @@ loader_main(struct loader_callbacks_v1 *cb, void *arg, int version, int ndisks) setenv("LINES", "24", 1); /* optional */ + /* + * Set custom environment variables + */ + i = 0; + while (1) { + var = CALLBACK(getenv, i++); + if (var == NULL) + break; + putenv(var); + } + archsw.arch_autoload = userboot_autoload; archsw.arch_getdev = userboot_getdev; archsw.arch_copyin = userboot_copyin; |