summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bhyveload/bhyveload.c
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2013-10-17 00:28:35 +0000
committerneel <neel@FreeBSD.org>2013-10-17 00:28:35 +0000
commit24a03e33cfed07a0a177ec644b81666406a76ce3 (patch)
tree58758e4bee94ba049066782ce69d754fa2cf137d /usr.sbin/bhyveload/bhyveload.c
parentc39edfbbf86784a5c5ddca4f4b1599f8e39313f0 (diff)
downloadFreeBSD-src-24a03e33cfed07a0a177ec644b81666406a76ce3.zip
FreeBSD-src-24a03e33cfed07a0a177ec644b81666406a76ce3.tar.gz
Add an option to bhyveload(8) that allows setting a loader environment variable
from the command line. The option syntax is "-e <name=value>". It may be used multiple times to set multiple environment variables. Reviewed by: grehan Requested by: alfred
Diffstat (limited to 'usr.sbin/bhyveload/bhyveload.c')
-rw-r--r--usr.sbin/bhyveload/bhyveload.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
index 6e541e8..4ce3df4 100644
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/disk.h>
+#include <sys/queue.h>
#include <machine/specialreg.h>
#include <machine/vmm.h>
@@ -498,23 +499,37 @@ cb_getmem(void *arg, uint64_t *ret_lowmem, uint64_t *ret_highmem)
vm_get_memory_seg(ctx, 4 * GB, ret_highmem, NULL);
}
-static const char *
-cb_getenv(void *arg, int num)
+struct env {
+ const char *str; /* name=value */
+ SLIST_ENTRY(env) next;
+};
+
+static SLIST_HEAD(envhead, env) envhead;
+
+static void
+addenv(const char *str)
{
- int max;
+ struct env *env;
- static const char * var[] = {
- "smbios.bios.vendor=BHYVE",
- "boot_serial=1",
- NULL
- };
+ env = malloc(sizeof(struct env));
+ env->str = str;
+ SLIST_INSERT_HEAD(&envhead, env, next);
+}
- max = sizeof(var) / sizeof(var[0]);
+static const char *
+cb_getenv(void *arg, int num)
+{
+ int i;
+ struct env *env;
+
+ i = 0;
+ SLIST_FOREACH(env, &envhead, next) {
+ if (i == num)
+ return (env->str);
+ i++;
+ }
- if (num < max)
- return (var[num]);
- else
- return (NULL);
+ return (NULL);
}
static struct loader_callbacks cb = {
@@ -553,8 +568,8 @@ usage(void)
{
fprintf(stderr,
- "usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] "
- "<vmname>\n", progname);
+ "usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] "
+ "[-e <name=value>] <vmname>\n", progname);
exit(1);
}
@@ -572,12 +587,16 @@ main(int argc, char** argv)
mem_size = 256 * MB;
disk_image = NULL;
- while ((opt = getopt(argc, argv, "d:h:m:")) != -1) {
+ while ((opt = getopt(argc, argv, "d:e:h:m:")) != -1) {
switch (opt) {
case 'd':
disk_image = optarg;
break;
+ case 'e':
+ addenv(optarg);
+ break;
+
case 'h':
host_base = optarg;
break;
@@ -638,5 +657,9 @@ main(int argc, char** argv)
if (disk_image) {
disk_fd = open(disk_image, O_RDONLY);
}
+
+ addenv("smbios.bios.vendor=BHYVE");
+ addenv("boot_serial=1");
+
func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0);
}
OpenPOWER on IntegriCloud