Merge change r198561 from projects/mips to head:

r198561 | thompsa | 2009-10-28 15:25:22 -0600 (Wed, 28 Oct 2009) | 4 lines
Allow a scratch buffer to be set in order to be able to use setenv() while
booting, before dynamic kenv is running. A few platforms implement their own
scratch+sprintf handling to save data from the boot environment.
This commit is contained in:
Warner Losh 2010-01-10 22:34:18 +00:00
parent 85277f1350
commit eae8e367c5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202050
2 changed files with 34 additions and 0 deletions

View File

@ -60,6 +60,8 @@ static MALLOC_DEFINE(M_KENV, "kenv", "kernel environment");
/* pointer to the static environment */
char *kern_envp;
static int env_len;
static int env_pos;
static char *kernenv_next(char *);
/* dynamic environment variables */
@ -208,6 +210,14 @@ kenv(td, uap)
return (error);
}
void
init_static_kenv(char *buf, size_t len)
{
kern_envp = buf;
env_len = len;
env_pos = 0;
}
/*
* Setup the dynamic kernel environment.
*/
@ -336,6 +346,26 @@ testenv(const char *name)
return (0);
}
static int
setenv_static(const char *name, const char *value)
{
int len;
if (env_pos >= env_len)
return (-1);
/* Check space for x=y and two nuls */
len = strlen(name) + strlen(value);
if (len + 3 < env_len - env_pos) {
len = sprintf(&kern_envp[env_pos], "%s=%s", name, value);
env_pos += len+1;
kern_envp[env_pos] = '\0';
return (0);
} else
return (-1);
}
/*
* Set an environment variable by name.
*/
@ -345,6 +375,9 @@ setenv(const char *name, const char *value)
char *buf, *cp, *oldenv;
int namelen, vallen, i;
if (dynamic_kenv == 0 && env_len > 0)
return (setenv_static(name, value));
KENV_CHECK;
namelen = strlen(name) + 1;

View File

@ -164,6 +164,7 @@ void critical_exit(void);
void init_param1(void);
void init_param2(long physpages);
void init_param3(long kmempages);
void init_static_kenv(char *, size_t);
void tablefull(const char *);
int kvprintf(char const *, void (*)(int, void*), void *, int,
__va_list) __printflike(1, 0);