git: 9front

Download patch

ref: 4a1d005a9a2318b99df31c92b2c8bcd11cffdb5a
parent: a4215757b347994d7fbcc3c826d3559fb8bfcc9c
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Tue Jun 14 17:03:03 EDT 2011

boot(8): handle flags and arguments in bootrc

--- a/sys/src/9/boot/boot.c
+++ b/sys/src/9/boot/boot.c
@@ -4,14 +4,10 @@
 #include <fcall.h>
 #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 @@
 		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 @@
 	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);
 }
--- a/sys/src/9/boot/boot.h
+++ b/sys/src/9/boot/boot.h
@@ -6,9 +6,6 @@
 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);
--- a/sys/src/9/boot/bootrc
+++ b/sys/src/9/boot/bootrc
@@ -8,8 +8,9 @@
 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 @@
 			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 @@
 	# 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 @@
 		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 @@
 	# 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
 }
 
@@ -139,6 +148,33 @@
 	bind -qa '#'$i /net
 
 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}
--