FreeBSD/sys/kern/kern_environment.c
/*
 * Populate the initial kernel environment.
 *
 * This is called very early in MD startup, either to provide a copy of the
 * environment obtained from a boot loader, or to provide an empty buffer into
 * which MD code can store an initial environment using kern_setenv() calls.
 *
 * When a copy of an initial environment is passed in, we start by scanning that
 * env for overrides to the compiled-in envmode and hintmode variables.
 *
 * If the global envmode is 1, the environment is initialized from the global
 * static_env[], regardless of the arguments passed.  This implements the env
 * keyword described in config(5).  In this case env_pos is set to env_len,
 * causing kern_setenv() to return -1 (if len > 0) or panic (if len == 0) until
 * the dynamic environment is available.  The envmode and static_env variables
 * are defined in env.c which is generated by config(8).
 *
 * If len is non-zero, the caller is providing an empty buffer.  The caller will
 * subsequently use kern_setenv() to add up to len bytes of initial environment
 * before the dynamic environment is available.
 *
 * If len is zero, the caller is providing a pre-loaded buffer containing
 * environment strings.  Additional strings cannot be added until the dynamic
 * environment is available.  The memory pointed to must remain stable at least
 * until sysinit runs init_dynamic_kenv().  If no initial environment is
 * available from the boot loader, passing a NULL pointer allows the static_env
 * to be installed if it is configured.
 */
Populate the initial kernel environment.
This is called very early in MD startup, either to provide a copy of the
environment obtained from a boot loader, or to provide an empty buffer into
which MD code can store an initial environment using kern_setenv() calls.

When a copy of an initial environment is passed in, we start by scanning that
env for overrides to the compiled-in envmode and hintmode variables.

If the global envmode is 1, the environment is initialized from the global
static_env[], regardless of the arguments passed.  This implements the env
keyword described in config(5).  In this case env_pos is set to env_len,
causing kern_setenv() to return -1 (if len > 0) or panic (if len == 0) until
the dynamic environment is available.  The envmode and static_env variables
are defined in env.c which is generated by config(8).

If len is non-zero, the caller is providing an empty buffer.  The caller will
subsequently use kern_setenv() to add up to len bytes of initial environment
before the dynamic environment is available.

If len is zero, the caller is providing a pre-loaded buffer containing
environment strings.  Additional strings cannot be added until the dynamic
environment is available.  The memory pointed to must remain stable at least
until sysinit runs init_dynamic_kenv().  If no initial environment is
available from the boot loader, passing a NULL pointer allows the static_env
to be installed if it is configured.
Populate the initial kernel environment . This is called very early in MD startup either to provide a copy of the environment obtained from a boot loader or to provide an empty buffer into which MD code can store an initial environment using kern_setenv () calls . When a copy of an initial environment is passed in we start by scanning that env for overrides to the compiled - in envmode and hintmode variables . If the global envmode is 1 the environment is initialized from the global static_env [] regardless of the arguments passed . This implements the env keyword described in config ( 5 ) . In this case env_pos is set to env_len causing kern_setenv () to return - 1 ( if len > 0 ) or panic ( if len == 0 ) until the dynamic environment is available . The envmode and static_env variables are defined in env . c which is generated by config ( 8 ) . If len is non - zero the caller is providing an empty buffer . The caller will subsequently use kern_setenv () to add up to len bytes of initial environment before the dynamic environment is available . If len is zero the caller is providing a pre - loaded buffer containing environment strings . Additional strings cannot be added until the dynamic environment is available . The memory pointed to must remain stable at least until sysinit runs init_dynamic_kenv () . If no initial environment is available from the boot loader passing a NULL pointer allows the static_env to be installed if it is configured .
void
init_static_kenv(char *buf, size_t len)
{
	char *cp;
	for (cp = buf; cp != NULL && cp[0] != '\0'; cp += strlen(cp) + 1) {
		if (strcmp(cp, "static_env.disabled=1") == 0)
			envmode = 0;
		if (strcmp(cp, "static_hints.disabled=1") == 0)
			hintmode = 0;
	}
	if (envmode == 1) {
		kern_envp = static_env;
		env_len = len;
		env_pos = len;
	} else {
		kern_envp = buf;
		env_len = len;
		env_pos = 0;
	}
}
void init_static_kenv ( char * buf , size_t len ) { char * cp ; for ( cp = buf ; cp != NULL && cp [ 0 ] != ' \0 ' ; cp += strlen ( cp ) + 1 ) { if ( strcmp ( cp , " " ) == 0 ) envmode = 0 ; if ( strcmp ( cp , " " ) == 0 ) hintmode = 0 ; } if ( envmode == 1 ) { kern_envp = static_env ; env_len = len ; env_pos = len ; } else { kern_envp = buf ; env_len = len ; env_pos = 0 ; } }
Populate the initial kernel environment.
Populate the initial kernel environment .