summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjchandra <jchandra@FreeBSD.org>2013-04-12 15:58:53 +0000
committerjchandra <jchandra@FreeBSD.org>2013-04-12 15:58:53 +0000
commitb9f386539e01f525540ae8c8b1d8ca0de681c2af (patch)
tree7ef4415a544c21eec74e4f0f00ef181393315dfe
parent8b2029265883067bf67b0fa209dd4f6e47c48e3f (diff)
downloadFreeBSD-src-b9f386539e01f525540ae8c8b1d8ca0de681c2af.zip
FreeBSD-src-b9f386539e01f525540ae8c8b1d8ca0de681c2af.tar.gz
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.
-rw-r--r--sys/kern/kern_environment.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c
index d60299b..3b04cb7 100644
--- a/sys/kern/kern_environment.c
+++ b/sys/kern/kern_environment.c
@@ -231,20 +231,23 @@ init_dynamic_kenv(void *data __unused)
kenvp = malloc((KENV_SIZE + 1) * sizeof(char *), M_KENV,
M_WAITOK | M_ZERO);
i = 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",
- cp);
- continue;
+ 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",
+ cp);
+ continue;
+ }
+ if (i < KENV_SIZE) {
+ kenvp[i] = malloc(len, M_KENV, M_WAITOK);
+ strcpy(kenvp[i++], cp);
+ } else
+ printf(
+ "WARNING: too many kenv strings, ignoring %s\n",
+ cp);
}
- if (i < KENV_SIZE) {
- kenvp[i] = malloc(len, M_KENV, M_WAITOK);
- strcpy(kenvp[i++], cp);
- } else
- printf(
- "WARNING: too many kenv strings, ignoring %s\n",
- cp);
}
kenvp[i] = NULL;
OpenPOWER on IntegriCloud