summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2012-11-12 22:38:54 +0000
committerneel <neel@FreeBSD.org>2012-11-12 22:38:54 +0000
commit2161a344ab74d16d5c913e681ead676d940d5459 (patch)
tree71ed8b0ffe15ee422aacffebe5fa8de260052c03
parent66400b6a1006fb0fe8ad5366b1586b7c080d461c (diff)
downloadFreeBSD-src-2161a344ab74d16d5c913e681ead676d940d5459.zip
FreeBSD-src-2161a344ab74d16d5c913e681ead676d940d5459.tar.gz
Add a callback function to userboot.so to fetch a list of environment
variables and pass them to the kernel. Reviewed by: dfr
-rw-r--r--sys/boot/userboot/test/test.c16
-rw-r--r--sys/boot/userboot/userboot.h14
-rw-r--r--sys/boot/userboot/userboot/main.c14
3 files changed, 42 insertions, 2 deletions
diff --git a/sys/boot/userboot/test/test.c b/sys/boot/userboot/test/test.c
index ef5c9a8..36258a7 100644
--- a/sys/boot/userboot/test/test.c
+++ b/sys/boot/userboot/test/test.c
@@ -364,6 +364,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 cb = {
.putc = test_putc,
.getc = test_getc,
@@ -391,6 +403,8 @@ struct loader_callbacks cb = {
.delay = test_delay,
.exit = test_exit,
.getmem = test_getmem,
+
+ .getenv = test_getenv,
};
void
@@ -450,5 +464,5 @@ main(int argc, char** argv)
term.c_lflag &= ~(ICANON|ECHO);
tcsetattr(0, TCSAFLUSH, &term);
- func(&cb, NULL, USERBOOT_VERSION_2, 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 ddb83a3..e38927e 100644
--- a/sys/boot/userboot/userboot.h
+++ b/sys/boot/userboot/userboot.h
@@ -31,6 +31,7 @@
*/
#define USERBOOT_VERSION_1 1
#define USERBOOT_VERSION_2 2
+#define USERBOOT_VERSION_3 3
/*
* Exit codes from the loader
@@ -176,9 +177,22 @@ struct loader_callbacks {
*/
void (*getmem)(void *arg, uint64_t *lowmem,
uint64_t *highmem);
+
/*
* ioctl interface to the disk device
*/
int (*diskioctl)(void *arg, int unit, u_long cmd,
void *data);
+
+ /*
+ * 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 374db17..4092b9b 100644
--- a/sys/boot/userboot/userboot/main.c
+++ b/sys/boot/userboot/userboot/main.c
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include "disk.h"
#include "libuserboot.h"
-#define USERBOOT_VERSION USERBOOT_VERSION_2
+#define USERBOOT_VERSION USERBOOT_VERSION_3
struct loader_callbacks *callbacks;
void *callbacks_arg;
@@ -70,6 +70,7 @@ void
loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
{
static char malloc[512*1024];
+ const char *var;
int i;
if (version != USERBOOT_VERSION)
@@ -107,6 +108,17 @@ loader_main(struct loader_callbacks *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;
OpenPOWER on IntegriCloud