svn commit: r202050 - in head/sys: kern sys

Warner Losh imp at FreeBSD.org
Sun Jan 10 22:34:19 UTC 2010


Author: imp
Date: Sun Jan 10 22:34:18 2010
New Revision: 202050
URL: http://svn.freebsd.org/changeset/base/202050

Log:
  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.

Modified:
  head/sys/kern/kern_environment.c
  head/sys/sys/systm.h

Modified: head/sys/kern/kern_environment.c
==============================================================================
--- head/sys/kern/kern_environment.c	Sun Jan 10 21:59:06 2010	(r202049)
+++ head/sys/kern/kern_environment.c	Sun Jan 10 22:34:18 2010	(r202050)
@@ -60,6 +60,8 @@ static MALLOC_DEFINE(M_KENV, "kenv", "ke
 
 /* 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 @@ done:
 	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 *val
 	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;

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h	Sun Jan 10 21:59:06 2010	(r202049)
+++ head/sys/sys/systm.h	Sun Jan 10 22:34:18 2010	(r202050)
@@ -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);


More information about the svn-src-all mailing list