Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Mar 2013 13:05:24 +0530
From:      "Jayachandran C." <jchandra@freebsd.org>
To:        FreeBSD Current <freebsd-current@freebsd.org>
Subject:   [PATCH] kenv issue when there is no static environment
Message-ID:  <CA%2B7sy7CL5VKD9WSJ%2B0mH5p-VUMYhLrjw0V4=PSzPRzwe_oNvFw@mail.gmail.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Planning to check the attached patch later this week, please let me
know if there any objections.

----

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 entry is usually empty and
confuses kenv(1). The entries added later by kenv(1) does not seem to
be added, even though they are.

The environment passed to the kernel can be empty when it is loaded
from a bootloader other than loader(8).


JC.

[-- Attachment #2 --]
Index: sys/kern/kern_environment.c
===================================================================
--- sys/kern/kern_environment.c	(revision 247765)
+++ sys/kern/kern_environment.c	(working copy)
@@ -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;
 
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2B7sy7CL5VKD9WSJ%2B0mH5p-VUMYhLrjw0V4=PSzPRzwe_oNvFw>