boot(8): handle flags and arguments in bootrc

cinap_lenrek 2011-06-14 21:03:03 +02:00
parent 11bbfa4aba
commit c4996be04f
3 changed files with 48 additions and 31 deletions

View File

@ -4,14 +4,10 @@
#include <fcall.h> #include <fcall.h>
#include "../boot/boot.h" #include "../boot/boot.h"
char cputype[64];
int mflag;
int fflag;
int kflag;
void void
boot(int argc, char *argv[]) boot(int argc, char *argv[])
{ {
char cputype[64];
char buf[32]; char buf[32];
fmtinstall('r', errfmt); fmtinstall('r', errfmt);
@ -37,18 +33,6 @@ boot(int argc, char *argv[])
print("\n"); print("\n");
} }
ARGBEGIN{
case 'k':
kflag = 1;
break;
case 'm':
mflag = 1;
break;
case 'f':
fflag = 1;
break;
}ARGEND
readfile("#e/cputype", cputype, sizeof(cputype)); readfile("#e/cputype", cputype, sizeof(cputype));
setenv("bootdisk", bootdisk, 0); setenv("bootdisk", bootdisk, 0);
setenv("cpuflag", cpuflag ? "1" : "0", 0); setenv("cpuflag", cpuflag ? "1" : "0", 0);
@ -60,5 +44,5 @@ boot(int argc, char *argv[])
snprint(buf, sizeof(buf), "/%s/bin", cputype); snprint(buf, sizeof(buf), "/%s/bin", cputype);
bind(buf, "/bin", MAFTER); bind(buf, "/bin", MAFTER);
bind("/rc/bin", "/bin", MAFTER); bind("/rc/bin", "/bin", MAFTER);
execl("/bin/bootrc", "bootrc", nil); exec("/bin/bootrc", argv);
} }

View File

@ -6,9 +6,6 @@ extern char* bootdisk;
extern char* rootdir; extern char* rootdir;
extern int (*cfs)(int); extern int (*cfs)(int);
extern int cpuflag; extern int cpuflag;
extern char cputype[];
extern int fflag;
extern int kflag;
extern void fatal(char*); extern void fatal(char*);
extern int readfile(char*, char*, int); extern int readfile(char*, char*, int);

View File

@ -8,8 +8,9 @@ bind -q '#p' /proc
for(i in S f k æ t) for(i in S f k æ t)
bind -a '#'^$i /dev >/dev/null >[2=1] bind -a '#'^$i /dev >/dev/null >[2=1]
for(i in init user nvram rootdir bootargs nobootprompt sysname \ for(i in init sysname user nvram rootdir bootdisk bootargs \
debugfactotum fs fsaddr auth authaddr){ nobootprompt debugfactotum \
fs fsaddr auth authaddr){
a=$$i a=$$i
$i=() $i=()
rm -f '#e'/$i '#ec'/$i /env/$i rm -f '#e'/$i '#ec'/$i /env/$i
@ -58,6 +59,7 @@ fn main{
ask bootargs ' is (tcp, local!device)' $bootargs ask bootargs ' is (tcp, local!device)' $bootargs
} }
if not bootargs=$nobootprompt if not bootargs=$nobootprompt
nobootprompt=()
mn=`{echo $bootargs | awk -F! '{print $1}'} mn=`{echo $bootargs | awk -F! '{print $1}'}
ma=`{echo $bootargs | sed 's/[^!]*!?//'} ma=`{echo $bootargs | sed 's/[^!]*!?//'}
switch(m$"mn){ switch(m$"mn){
@ -73,8 +75,11 @@ fn main{
# authentication agent # authentication agent
if(! test -f /srv/factotum){ if(! test -f /srv/factotum){
x=(/boot/factotum -sfactotum) x=(/boot/factotum -sfactotum)
if(~ $cpuflag 1) if(~ $cpuflag 1){
x=($x -S) x=($x -S)
if(~ -k $ff)
x=($x -k)
}
if not if not
x=($x -u) x=($x -u)
if(! ~ $#authaddr 0) if(! ~ $#authaddr 0)
@ -96,6 +101,17 @@ fn main{
rootdir=/root rootdir=/root
must mount -c /srv/boot $rootdir must mount -c /srv/boot $rootdir
# compile init command
if(~ $#init 0){
init=/$cputype/init
if(~ $cpuflag 1)
init=($init -c)
if not
init=($init -t)
if(~ -m $ff)
init=($init -m)
}
# remove enviroment variables # remove enviroment variables
rm -f /env/^$mt /env/? /env/?? '/env/fn#'* rm -f /env/^$mt /env/? /env/?? '/env/fn#'*
@ -111,13 +127,6 @@ fn main{
# remove the remaining temporary root # remove the remaining temporary root
/mnt/broot/$cputype/bin/unmount /mnt/broot /mnt/broot/$cputype/bin/unmount /mnt/broot
if(~ $#init 0){
init=/$cputype/init
if(~ $cpuflag 1)
init=($init -c)
if not
init=($init -t)
}
exec $init exec $init
} }
@ -140,6 +149,33 @@ for(i in I l^(0 1 2 3))
configlocal # add partitions and binds configlocal # add partitions and binds
# boot(8) command line arguments
ff=()
aa=()
while(! ~ $#* 0){
if(~ $1 -*){
if(! ~ $1 -u*){
if(~ $1 -*f*)
ff=($ff -f)
if(~ $1 -*k*)
ff=($ff -k)
if(~ $1 -*m*)
ff=($ff -m)
}
shift
}
if not {
while(! ~ $#* 0){
aa=($aa $1)
shift
}
}
}
if(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){
bootargs=$aa
nobootprompt=$aa
}
while(){ while(){
@{main} @{main}