Fix kenv behavior when there is no static environment

In case where there are no static kernel environment entries, the
function init_dynamic_kenv() adds an incorrect entry at position 0 of
the dynamic kernel environment. This in turn causes kenv(1) to print
and empty list even though there are dynamic entries added later.

Fix this by checking env_pos in init_dynamic_kenv() and adding dynamic
entries only if there are static entries.
This commit is contained in:
Jayachandran C. 2013-04-12 15:58:53 +00:00
parent 6e0f89a4b4
commit 15f9c9ed69

View File

@ -231,10 +231,12 @@ init_dynamic_kenv(void *data __unused)
kenvp = malloc((KENV_SIZE + 1) * sizeof(char *), M_KENV,
M_WAITOK | M_ZERO);
i = 0;
if (env_pos > 0) {
for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) {
len = strlen(cp) + 1;
if (len > KENV_MNAMELEN + 1 + KENV_MVALLEN + 1) {
printf("WARNING: too long kenv string, ignoring %s\n",
printf(
"WARNING: too long kenv string, ignoring %s\n",
cp);
continue;
}
@ -246,6 +248,7 @@ init_dynamic_kenv(void *data __unused)
"WARNING: too many kenv strings, ignoring %s\n",
cp);
}
}
kenvp[i] = NULL;
mtx_init(&kenv_lock, "kernel environment", NULL, MTX_DEF);