summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfw/lib/fwstart20
-rwxr-xr-xfw/test/fwtest.rc36
2 files changed, 53 insertions, 3 deletions
diff --git a/fw/lib/fwstart b/fw/lib/fwstart
index 00b4d3a..ce89691 100755
--- a/fw/lib/fwstart
+++ b/fw/lib/fwstart
@@ -38,9 +38,23 @@ fn rulesfor {
' $cfg
}
-# each card gets its own control directory; mntgen makes them appear
+# Each card gets its own control directory; mntgen makes them appear.
+#
+# mount(2) needs the mount point to exist, so mntgen cannot make /mnt/fw
+# and this used to run it only when /mnt/fw was missing - which is the
+# one case where it fails. So the directory first, and then mntgen only
+# if it is not already there: under mntgen every name exists, which is
+# the test.
+#
+# mntgen and fw both leave a server behind, and a server started from a
+# shell keeps that shell's file descriptors. Started from the console -
+# or from a serial shell, which is where this gets tried first - that
+# means a daemon sitting on the console's input, which looks exactly
+# like a wedged terminal. Give them nothing to hold.
if(! test -d /mnt/fw)
- mntgen /mnt/fw
+ mkdir -p /mnt/fw
+if(! test -d /mnt/fw/is-mntgen-here)
+ mntgen /mnt/fw </dev/null >/dev/null >[2]/dev/null
for(name in `{cards}){
dev=/net/$name
@@ -52,7 +66,7 @@ for(name in `{cards}){
if not if(! test -f $rules)
echo fwstart: $rules missing, $name skipped >[1=2]
if not {
- fw -m /mnt/fw/$name -e $dev $rules
+ fw -m /mnt/fw/$name -e $dev $rules </dev/null >/dev/null
if(~ $status '')
echo fwstart: $name filtered by $rules
if not
diff --git a/fw/test/fwtest.rc b/fw/test/fwtest.rc
index 15ea531..d4222a8 100755
--- a/fw/test/fwtest.rc
+++ b/fw/test/fwtest.rc
@@ -30,6 +30,11 @@ src=$2
if(~ $#src 0)
src=/sys/src/cmd/fw
+# where the scripts are, likewise
+lib=$3
+if(~ $#lib 0)
+ lib=/lib/fw
+
tmp=/tmp/fwtest.$pid
mkdir -p $tmp
nA=$tmp/nA
@@ -391,6 +396,37 @@ echo '== packets, between two stacks'
stopfw $nA $nB
}
+echo '== fwstart'
+if(test -f $lib/fwstart)
+@{
+ rfork n
+ # /mnt as it is at boot: a real directory, with no fw in it yet.
+ # -c because without it the bound directory forbids creation and
+ # fwstart's mkdir fails for a reason the real /mnt would not give.
+ mkdir -p $tmp/mnt
+ bind -c $tmp/mnt /mnt
+ >$tmp/marker
+ echo 'fw=nosuchether rules='^$tmp/empty.ndb > $tmp/fwcfg
+ @{ rc $lib/fwstart $tmp/fwcfg } <$tmp/marker >$tmp/fwout >[2=1]
+ sleep 1
+
+ # mount(2) needs the mount point to exist, so the old
+ # "mntgen /mnt/fw only if /mnt/fw is missing" ran it exactly when
+ # it could not work, and every card's control directory failed
+ r=`{if(test -d /mnt/fw/whatever) echo yes; if not echo no}
+ check 'a control directory appears for each card' yes $"r
+
+ r=`{grep -c nosuchether $tmp/fwout}
+ check 'a card that is not there is reported and skipped' 1 $"r
+
+ # anything it leaves running holds the descriptors it was started
+ # with, and on a console that is the console
+ r=`{cat /proc/*/fd >[2]/dev/null | grep -c $tmp/marker}
+ check 'and nothing it started kept our descriptors' 0 $"r
+}
+if not
+ echo ' skip no '^$lib^'/fwstart'
+
echo '== the test cleans up after itself'
r=`{nfw}
check 'no fw processes are left running' $"fwbefore $"r