From owner-svn-src-projects@FreeBSD.ORG Tue Nov 6 21:36:38 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6276C1B9; Tue, 6 Nov 2012 21:36:38 +0000 (UTC) (envelope-from neel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 484BB8FC15; Tue, 6 Nov 2012 21:36:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qA6Lac88056930; Tue, 6 Nov 2012 21:36:38 GMT (envelope-from neel@svn.freebsd.org) Received: (from neel@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qA6LacZc056926; Tue, 6 Nov 2012 21:36:38 GMT (envelope-from neel@svn.freebsd.org) Message-Id: <201211062136.qA6LacZc056926@svn.freebsd.org> From: Neel Natu Date: Tue, 6 Nov 2012 21:36:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r242675 - in projects/bhyve/sys/boot/userboot: . test userboot X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2012 21:36:38 -0000 Author: neel Date: Tue Nov 6 21:36:37 2012 New Revision: 242675 URL: http://svnweb.freebsd.org/changeset/base/242675 Log: 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 Modified: projects/bhyve/sys/boot/userboot/test/test.c projects/bhyve/sys/boot/userboot/userboot.h projects/bhyve/sys/boot/userboot/userboot/main.c Modified: projects/bhyve/sys/boot/userboot/test/test.c ============================================================================== --- projects/bhyve/sys/boot/userboot/test/test.c Tue Nov 6 21:16:45 2012 (r242674) +++ projects/bhyve/sys/boot/userboot/test/test.c Tue Nov 6 21:36:37 2012 (r242675) @@ -339,6 +339,18 @@ test_getmem(void *arg, uint64_t *lowmem, *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); } Modified: projects/bhyve/sys/boot/userboot/userboot.h ============================================================================== --- projects/bhyve/sys/boot/userboot/userboot.h Tue Nov 6 21:16:45 2012 (r242674) +++ projects/bhyve/sys/boot/userboot/userboot.h Tue Nov 6 21:36:37 2012 (r242675) @@ -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); }; Modified: projects/bhyve/sys/boot/userboot/userboot/main.c ============================================================================== --- projects/bhyve/sys/boot/userboot/userboot/main.c Tue Nov 6 21:16:45 2012 (r242674) +++ projects/bhyve/sys/boot/userboot/userboot/main.c Tue Nov 6 21:36:37 2012 (r242675) @@ -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 * 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;