ref: c165b88513ed831bdd1022ff613230f190566eba
parent: 4345bb5a9bdbbe79891ddd3b7b1c82e9a7752d95
author: cinap_lenrek <cinap_lenrek@localhost>
date: Thu Apr 21 18:22:25 EDT 2011
boot(8): cleanup enviroment variables before init
--- a/rc/bin/termrc
+++ b/rc/bin/termrc
@@ -8,6 +8,7 @@
# bind all likely devices (#S was bound in boot)
for(i in f t m v L P u U '$' Σ κ)
/bin/bind -a '#'^$i /dev >/dev/null >[2=1]
+rm -f /env/i
# set up any partitions
diskparts
@@ -16,7 +17,7 @@
disk=`{ls /dev/sd*/swap >[2]/dev/null}if (! ~ $#disk 0)
swap $disk(1) >/dev/null >[2=1]
-rm /env/disk
+rm -f /env/disk
# we do this before we have a name. we may need to do network
# setup so that we can get a name.
@@ -107,6 +108,7 @@
}
}
}
+rm -f '/env/fn#ask'
usbstart
if (test -f /dev/apm)
--- a/sys/src/9/boot/bootrc
+++ b/sys/src/9/boot/bootrc
@@ -1,21 +1,8 @@
-# TODO
-# settime
-# handle rootspec
-# handle rootdir
-# clean rc environment before running init(8)
-# kfs
-# caching
-
rfork e
-# boot methods
-mlocal = (configlocal connectlocal)
-mtcp = (configtcp connecttcp)
-mtab = (mlocal mtcp)
-config=1
-connect=2
-. /rc/lib/local.rc
+mt=()
. /rc/lib/tcp.rc
+. /rc/lib/local.rc
fn fatal {echo $*
@@ -29,7 +16,7 @@
fn ask {echo -n $1
echo -n $2
- if(! ~ $#3 0){+ if(! ~ $3 ''){echo -n ' ['
echo -n $3
echo -n '] '
@@ -45,38 +32,33 @@
ask $*
}
-fn readmethod{- found=0
- while(~ $found 0){+fn getmethod{+ mp=()
+ while(~ $#mp 0){ if(~ $#nobootprompt 0){echo
showlocaldevs
- ask bootargs ' are? (tcp, local!device)' $"bootargs
+ ask bootargs ' are? (tcp, local!device)' $bootargs
}
if not {bootargs=$nobootprompt
nobootprompt=()
}
- method=`{echo $bootargs | awk -F! '{print $1}'}- NF=`{echo $bootargs | awk -F! '{print NF}'}- for(i in `{seq 1 $#mtab}){- if(~ $mtab($i) m^$method)
- found=$i
+ mn=`{echo $bootargs | awk -F! '{print $1}'}+ ma=`{echo $bootargs | awk -F! '{print $2}'}+ for(i in `{seq 1 $#mt}){+ if(~ $mt($i) m^$mn)
+ mp=$$mt($i)
}
- if(~ $found 0)
- echo method $method not found
}
- methodarg = `{echo $bootargs | awk -F! '{print $2}'}- mp = $$mtab($found)
}
fn main{rm -f /srv/boot
- readmethod
- $mp($config) $methodarg
+ getmethod
- switch($method){+ switch($mn){case local
islocal=1
case hybrid
@@ -83,6 +65,9 @@
ishybrid=1
}
+ # config method
+ $mp(1) $ma
+
# authentication agent
if(! test -f /srv/factotum){x=(/boot/factotum -sfactotum)
@@ -97,8 +82,8 @@
must $x
}
- # connect to the root file system
- $mp($connect) $methodarg
+ # connect method
+ $mp(2) $ma
# mount root filesystem
must mount -c /srv/boot /root
@@ -107,6 +92,9 @@
if(test -x /dev/swap)
echo -n start >/dev/swap
+ # remove enviroment variables
+ rm -f /env/^$mt /env/? /env/?? '/env/fn#'*
+
# remove part of our temporary root
/mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
/mnt/broot/$cputype/bin/unmount /rc/bin /bin
@@ -142,7 +130,6 @@
if(test -e '#u'){bind -a '#u' /dev
usb/usbd
- sleep 1
}
if(! ~ $#kbmap 0){@@ -154,6 +141,6 @@
configlocal # add partitions and binds
while()@{- rfork n
+ rfork ne
main
}
--- a/sys/src/9/boot/local.rc
+++ b/sys/src/9/boot/local.rc
@@ -20,8 +20,6 @@
fn configlocal{ if(~ $pcload 1){ kern=`{echo $* | sed 's,.*!(.*)$,\1,g'}-
- # for now we only allow kernels in the same dev/part of $methodargs
if(~ $#kern 0 || ! ~ $#bootfile 0)
kern=`{echo $bootfile | sed 's,.*!(.*)$,\1,g'}}
@@ -41,3 +39,6 @@
}
{$t -s -f $* &} <[0=1] | echo 0 >/srv/boot}
+
+mlocal=(configlocal connectlocal)
+mt=(mlocal $mt)
--- a/sys/src/9/boot/tcp.rc
+++ b/sys/src/9/boot/tcp.rc
@@ -3,7 +3,7 @@
fn configtcp{# bind in an ip interface
for(i in I l`{seq 0 3})- bind -a '#'$i /net >/dev/null >[2=1]
+ bind -qa '#'$i /net
must ip/ipconfig -p $*
@@ -12,9 +12,9 @@
if(~ $#auth 0)
auth=`{awk -F'=' '/auth=/{print $2; exit}' /net/ndb}if(~ $#fs 0)
- ask fs ' ip is?' $"auth
+ ask fs ' ip is?' $auth
if(~ $#auth 0)
- ask auth ' ip is?' $"fs
+ ask auth ' ip is?' $fs
fsaddr=tcp!$fs!564
authaddr=tcp!$auth!567
@@ -23,3 +23,6 @@
fn connecttcp{srv -q $"fsaddr boot
}
+
+mtcp=(configtcp connecttcp)
+mt=(mtcp $mt)
--
⑨