From c4996be04fc2a79878fa56a4268fb851b2a6568e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 14 Jun 2011 21:03:03 +0200 Subject: [PATCH] boot(8): handle flags and arguments in bootrc --- sys/src/9/boot/boot.c | 20 ++-------------- sys/src/9/boot/boot.h | 3 --- sys/src/9/boot/bootrc | 56 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/sys/src/9/boot/boot.c b/sys/src/9/boot/boot.c index 655545d4c..5d876fa34 100644 --- a/sys/src/9/boot/boot.c +++ b/sys/src/9/boot/boot.c @@ -4,14 +4,10 @@ #include #include "../boot/boot.h" -char cputype[64]; -int mflag; -int fflag; -int kflag; - void boot(int argc, char *argv[]) { + char cputype[64]; char buf[32]; fmtinstall('r', errfmt); @@ -37,18 +33,6 @@ boot(int argc, char *argv[]) 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)); setenv("bootdisk", bootdisk, 0); setenv("cpuflag", cpuflag ? "1" : "0", 0); @@ -60,5 +44,5 @@ boot(int argc, char *argv[]) snprint(buf, sizeof(buf), "/%s/bin", cputype); bind(buf, "/bin", MAFTER); bind("/rc/bin", "/bin", MAFTER); - execl("/bin/bootrc", "bootrc", nil); + exec("/bin/bootrc", argv); } diff --git a/sys/src/9/boot/boot.h b/sys/src/9/boot/boot.h index 1734b06fe..4e70a1f60 100644 --- a/sys/src/9/boot/boot.h +++ b/sys/src/9/boot/boot.h @@ -6,9 +6,6 @@ extern char* bootdisk; extern char* rootdir; extern int (*cfs)(int); extern int cpuflag; -extern char cputype[]; -extern int fflag; -extern int kflag; extern void fatal(char*); extern int readfile(char*, char*, int); diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index 5b745483c..ccf4e809b 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -8,8 +8,9 @@ bind -q '#p' /proc for(i in S f k æ t) bind -a '#'^$i /dev >/dev/null >[2=1] -for(i in init user nvram rootdir bootargs nobootprompt sysname \ - debugfactotum fs fsaddr auth authaddr){ +for(i in init sysname user nvram rootdir bootdisk bootargs \ + nobootprompt debugfactotum \ + fs fsaddr auth authaddr){ a=$$i $i=() rm -f '#e'/$i '#ec'/$i /env/$i @@ -58,6 +59,7 @@ fn main{ ask bootargs ' is (tcp, local!device)' $bootargs } if not bootargs=$nobootprompt + nobootprompt=() mn=`{echo $bootargs | awk -F! '{print $1}'} ma=`{echo $bootargs | sed 's/[^!]*!?//'} switch(m$"mn){ @@ -73,8 +75,11 @@ fn main{ # authentication agent if(! test -f /srv/factotum){ x=(/boot/factotum -sfactotum) - if(~ $cpuflag 1) + if(~ $cpuflag 1){ x=($x -S) + if(~ -k $ff) + x=($x -k) + } if not x=($x -u) if(! ~ $#authaddr 0) @@ -96,6 +101,17 @@ fn main{ rootdir=/root 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 rm -f /env/^$mt /env/? /env/?? '/env/fn#'* @@ -111,13 +127,6 @@ fn main{ # remove the remaining temporary root /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 } @@ -140,6 +149,33 @@ for(i in I l^(0 1 2 3)) 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(){ @{main}