From 76cb0cadf1469e60fd6b4aa0c0dc10ef98700220 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Mon, 27 Aug 2001 05:11:53 +0000 Subject: [PATCH] Enable hardwiring of things like tunables from embedded enironments that do not start from loader(8). --- sys/alpha/alpha/machdep.c | 5 ++- sys/amd64/amd64/machdep.c | 4 ++- sys/conf/Makefile.alpha | 9 ++++-- sys/conf/Makefile.i386 | 9 ++++-- sys/conf/Makefile.ia64 | 9 ++++-- sys/conf/Makefile.pc98 | 9 ++++-- sys/conf/Makefile.powerpc | 9 ++++-- sys/conf/Makefile.sparc64 | 9 ++++-- sys/i386/i386/machdep.c | 4 ++- sys/ia64/ia64/machdep.c | 5 ++- sys/pc98/i386/machdep.c | 4 ++- sys/pc98/pc98/machdep.c | 4 ++- sys/sys/systm.h | 2 ++ usr.sbin/config/config.h | 2 ++ usr.sbin/config/config.y | 8 +++++ usr.sbin/config/configvers.h | 2 +- usr.sbin/config/lang.l | 1 + usr.sbin/config/mkmakefile.c | 62 ++++++++++++++++++++++++++++-------- 18 files changed, 119 insertions(+), 38 deletions(-) diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index 54c7b65ac595..ea385be9b328 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -655,7 +655,10 @@ alpha_init(pfn, ptb, bim, bip, biv) /* Get the loader(8) metadata */ preload_metadata = (caddr_t)bootinfo.modptr; - kern_envp = bootinfo.envp; + if (envmode == 1) + kern_envp = static_env; + else + kern_envp = bootinfo.envp; /* Do basic tuning, hz etc */ init_param(); diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index c1148e91f2e9..95f729dced7e 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1813,7 +1813,9 @@ init386(first) } else { metadata_missing = 1; } - if (bootinfo.bi_envp) + if (envmode == 1) + kern_envp = static_env; + else if (bootinfo.bi_envp) kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE; /* Init basic tunables, hz etc */ diff --git a/sys/conf/Makefile.alpha b/sys/conf/Makefile.alpha index 2a2a1ef9f76e..e9c5ade76cc4 100644 --- a/sys/conf/Makefile.alpha +++ b/sys/conf/Makefile.alpha @@ -17,7 +17,7 @@ # # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel @@ -88,10 +88,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o config.o hack.So +SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -e locorestart \ -export-dynamic -dynamic-linker /red/herring \ @@ -357,6 +357,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/conf/Makefile.i386 b/sys/conf/Makefile.i386 index 5cf3310e9d3a..aea5affc08a7 100644 --- a/sys/conf/Makefile.i386 +++ b/sys/conf/Makefile.i386 @@ -17,7 +17,7 @@ # # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel @@ -91,10 +91,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o config.o hack.So +SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -export-dynamic -dynamic-linker /red/herring \ -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o @@ -315,6 +315,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/conf/Makefile.ia64 b/sys/conf/Makefile.ia64 index 6c23e24ff391..56d44a540c5f 100644 --- a/sys/conf/Makefile.ia64 +++ b/sys/conf/Makefile.ia64 @@ -27,7 +27,7 @@ OBJDUMP= ia64-unknown-linux-objdump MACHINE_ARCH= ia64 # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel @@ -101,10 +101,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o config.o \ +SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o \ # hack.So ski can't cope with dynamic relocs SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -e locorestart \ @@ -326,6 +326,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/conf/Makefile.pc98 b/sys/conf/Makefile.pc98 index c995942219aa..d082fa6413c7 100644 --- a/sys/conf/Makefile.pc98 +++ b/sys/conf/Makefile.pc98 @@ -19,7 +19,7 @@ # # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel @@ -93,10 +93,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o config.o hack.So +SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -export-dynamic -dynamic-linker /red/herring \ -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o @@ -319,6 +319,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/conf/Makefile.powerpc b/sys/conf/Makefile.powerpc index 382e9bfe2e89..8b492fa8a5f3 100644 --- a/sys/conf/Makefile.powerpc +++ b/sys/conf/Makefile.powerpc @@ -17,7 +17,7 @@ # # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Temporary stuff while we're still embryonic NO_MODULES?= yes @@ -94,10 +94,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o config.o hack.So +SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -export-dynamic -dynamic-linker /red/herring \ -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o @@ -318,6 +318,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/conf/Makefile.sparc64 b/sys/conf/Makefile.sparc64 index 7c578d1905c3..5cc86a8ba35e 100644 --- a/sys/conf/Makefile.sparc64 +++ b/sys/conf/Makefile.sparc64 @@ -32,7 +32,7 @@ CWARNFLAGS= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \ -ansi # Which version of config(8) is required. -%VERSREQ= 500007 +%VERSREQ= 500008 # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel @@ -98,10 +98,10 @@ NORMAL_M= perl5 $S/kern/makeobjops.pl -c $<; \ ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c GEN_CFILES= $S/$M/$M/genassym.c -SYSTEM_CFILES= vnode_if.c hints.c config.c +SYSTEM_CFILES= vnode_if.c hints.c env.c config.c SYSTEM_SFILES= $S/$M/$M/locore.s $S/$M/$M/exception.s SYSTEM_DEP= Makefile ${SYSTEM_OBJS} -SYSTEM_OBJS= locore.o exception.o vnode_if.o ${OBJS} hints.o config.o hack.So +SYSTEM_OBJS= locore.o exception.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \ -export-dynamic -dynamic-linker /red/herring \ -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o @@ -329,6 +329,9 @@ vers.o: hints.o: hints.c ${NORMAL_C} +env.o: env.c + ${NORMAL_C} + vnode_if.c: $S/kern/vnode_if.pl $S/kern/vnode_if.src perl5 $S/kern/vnode_if.pl -c $S/kern/vnode_if.src diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index c1148e91f2e9..95f729dced7e 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -1813,7 +1813,9 @@ init386(first) } else { metadata_missing = 1; } - if (bootinfo.bi_envp) + if (envmode == 1) + kern_envp = static_env; + else if (bootinfo.bi_envp) kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE; /* Init basic tunables, hz etc */ diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c index 8a6d335c210b..04b9e1acee5d 100644 --- a/sys/ia64/ia64/machdep.c +++ b/sys/ia64/ia64/machdep.c @@ -387,7 +387,10 @@ ia64_init() if (bootinfo.kernend) kernend = round_page(bootinfo.kernend); preload_metadata = (caddr_t)bootinfo.modptr; - kern_envp = bootinfo.envp; + if (envmode == 1) + kern_envp = static_env; + else + kern_envp = bootinfo.envp; /* Init basic tunables, including hz */ init_param(); diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c index c0d5eff9e8e3..c6768ac37dca 100644 --- a/sys/pc98/i386/machdep.c +++ b/sys/pc98/i386/machdep.c @@ -1877,7 +1877,9 @@ init386(first) } else { metadata_missing = 1; } - if (bootinfo.bi_envp) + if (envmode == 1) + kern_envp = static_env; + else if (bootinfo.bi_envp) kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE; /* Init basic tunables, hz etc */ diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c index c0d5eff9e8e3..c6768ac37dca 100644 --- a/sys/pc98/pc98/machdep.c +++ b/sys/pc98/pc98/machdep.c @@ -1877,7 +1877,9 @@ init386(first) } else { metadata_missing = 1; } - if (bootinfo.bi_envp) + if (envmode == 1) + kern_envp = static_env; + else if (bootinfo.bi_envp) kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE; /* Init basic tunables, hz etc */ diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 469a490fa9a5..5b524816543d 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -178,6 +178,8 @@ char *getenv __P((const char *name)); int getenv_int __P((const char *name, int *data)); quad_t getenv_quad __P((const char *name, quad_t *data)); extern char *kern_envp; +extern char *static_env; +extern int envmode; #ifdef APM_FIXUP_CALLTODO void adjust_timeout_calltodo __P((struct timeval *time_change)); diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 8b6606fabc46..7c493d83cec7 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -122,8 +122,10 @@ struct opt_list { } *otab; extern char *ident; +extern char *env; extern char *hints; extern int do_trace; +extern int envmode; extern int hintmode; char *get_word(FILE *); diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index 5f1577471ac5..b1f5f2b47e5d 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -9,6 +9,7 @@ %token CONFIG %token CPU %token DEVICE +%token ENV %token EQUALS %token HINTS %token IDENT @@ -75,6 +76,8 @@ static struct device *curp = 0; struct device *dtab; char *ident; +char *env; +int envmode; char *hints; int hintmode; int yyline; @@ -145,6 +148,11 @@ Config_spec: = { maxusers = $2; } | PROFILE NUMBER = { profiling = $2; } | + ENV ID + = { + env = $2; + envmode = 1; + } | HINTS ID = { hints = $2; diff --git a/usr.sbin/config/configvers.h b/usr.sbin/config/configvers.h index 3dbb96db0309..e62ab7b7f80d 100644 --- a/usr.sbin/config/configvers.h +++ b/usr.sbin/config/configvers.h @@ -8,4 +8,4 @@ * * $FreeBSD$ */ -#define CONFIGVERS 500007 +#define CONFIGVERS 500008 diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index 63e46e4823c3..f7f6ee058ac1 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -67,6 +67,7 @@ struct kt { { "config", CONFIG }, { "cpu", CPU }, { "device", DEVICE }, + { "env", ENV }, { "hints", HINTS }, { "ident", IDENT }, { "machine", ARCH }, /* MACHINE is defined in /sys/param.h */ diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 45516fc3889f..29a5cb097c71 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -206,19 +206,6 @@ makefile(void) ofp = fopen(path("hints.c.new"), "w"); if (ofp == NULL) err(1, "%s", path("hints.c.new")); -#if 0 - /* - * This is causing more pain than it is worth. And besides, the - * release has been fixed so that this isn't necessary anymore. - * The boot floppies load hints now. - */ - if (hintmode == 0) { - snprintf(line, sizeof(line), "%s.hints", PREFIX); - ifp = fopen(line, "r"); - if (ifp) - hintmode = 2; - } -#endif fprintf(ofp, "int hintmode = %d;\n", hintmode); fprintf(ofp, "char static_hints[] = {\n"); if (ifp) { @@ -257,6 +244,55 @@ makefile(void) fclose(ifp); fclose(ofp); moveifchanged(path("hints.c.new"), path("hints.c")); + + if (env) { + ifp = fopen(env, "r"); + if (ifp == NULL) + err(1, "%s", env); + } else { + ifp = NULL; + } + ofp = fopen(path("env.c.new"), "w"); + if (ofp == NULL) + err(1, "%s", path("env.c.new")); + fprintf(ofp, "int envmode = %d;\n", envmode); + fprintf(ofp, "char static_env[] = {\n"); + if (ifp) { + while (fgets(line, BUFSIZ, ifp) != 0) { + /* zap trailing CR and/or LF */ + while ((s = rindex(line, '\n')) != NULL) + *s = '\0'; + while ((s = rindex(line, '\r')) != NULL) + *s = '\0'; + /* remove # comments */ + s = index(line, '#'); + if (s) + *s = '\0'; + /* remove any whitespace and " characters */ + s = line; + while (*s) { + if (*s == ' ' || *s == '\t' || *s == '"') { + while (*s) { + s[0] = s[1]; + s++; + } + /* start over */ + s = line; + continue; + } + s++; + } + /* anything left? */ + if (*line == '\0') + continue; + fprintf(ofp, "\"%s\\0\"\n", line); + } + } + fprintf(ofp, "\"\\0\"\n};\n"); + if (ifp) + fclose(ifp); + fclose(ofp); + moveifchanged(path("env.c.new"), path("env.c")); } /*