ref: 5868b80e87bd095bd690dd69ddd39e2c5c61e3a9
parent: 1f9b53648cf0133647696c963bb412bab6f2313f
author: iru <devnull@localhost>
date: Sun Apr 17 13:25:55 EDT 2011
Add /sys/src/9/boot/tread, a tool to read a line with a timeout. While here, remove boot(8) references to pcload.
--- a/sys/src/9/boot/bootmkfile
+++ b/sys/src/9/boot/bootmkfile
@@ -16,3 +16,7 @@
%.$O: $BOOTDIR/%.c
$CC -I$BOOTDIR $CFLAGS $BOOTDIR/$stem.c
+
+tread: tread.c
+ $CC tread.c
+ $LD -o tread tread.8
--- a/sys/src/9/boot/bootrc
+++ b/sys/src/9/boot/bootrc
@@ -67,11 +67,8 @@
timeo=5
resp=()
while(~ $#resp 0){- if(~ $#pcload 0)
- echo -n 'root is from: '
- if not
- echo -n 'kernel is at: '
- resp=`{read}+ echo -n 'root is from: '
+ resp=`{tread $timeo} if(! ~ $status ''){bootconf # set configuration from file
if(! ~ $#nobootprompt 0)
@@ -78,11 +75,9 @@
bootargs=$nobootprompt
resp=$bootargs
}
- if(~ $resp !rc){+ if(~ $resp !rc)
rc -i
- resp=()
- }
- timo=0
+ timeo=0
}
method=`{echo $resp | awk -F! '{print $1}'}@@ -103,9 +98,6 @@
fn authentication{ if(! test -f /srv/factotum){- # in pcload we only need to read the kernel
- if(~ $pcload 1)
- user=none
x=(auth/factotum -sfactotum)
if(~ $cpuflag 1)
x=($x -kS)
@@ -142,10 +134,6 @@
$mp($connect)
must mount -c /srv/boot /root
- if(~ $pcload 1){- echo reboot /root/$kern >/dev/reboot
- fatal kernel load failed: $kern
- }
swapproc
--- a/sys/src/9/boot/conf.rc
+++ b/sys/src/9/boot/conf.rc
@@ -28,8 +28,7 @@
}
fn findconf{- # search cd/dvd drives first
- for(d in $cddevs /dev/sd* /dev/fd*disk)
+ for(d in /dev/sd*)
for(p in `{ls $d}){ if(~ $found 0){confmount $p
--- a/sys/src/9/boot/local.rc
+++ b/sys/src/9/boot/local.rc
@@ -5,13 +5,6 @@
fstype=`{echo $disk | sed 's,.*/(.*)$,\1,g'} disk=`{echo $disk | sed 's,(.*)/.*$,\1,'}- if(~ $pcload 1){- kern=`{echo $methodarg | 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'}- }
diskparts
}
--- /dev/null
+++ b/sys/src/9/boot/tread.c
@@ -1,0 +1,73 @@
+#include <u.h>
+#include <libc.h>
+
+int c;
+
+int
+alarmed(void *a, char *msg)
+{+ USED(a);
+ USED(msg);
+ if(!c)
+ exits("timedout");+ noted(NCONT);
+ return 1;
+}
+
+void
+readline(int fd, char *buf, int nbuf)
+{+ int i, n;
+
+ i = 0;
+ while(i < nbuf-1){+ n = read(fd, &c, sizeof c);
+ alarm(0);
+ c &= 0xff;
+ write(fd, &c, 1);
+ if(n != 1 || c == '\04' || c == '\177'){+ i = 0;
+ break;
+ } else if(c == '\n')
+ break;
+ else if(c == '\b' && i > 0)
+ --i;
+ else if(c == ('u' & 037)){+ c = '\b';
+ for(n=0; n <= i; n++)
+ write(fd, &c, 1);
+ i = 0;
+ } else
+ buf[i++] = c;
+ }
+ buf[i] = 0;
+}
+
+void
+main(int argc, char *argv[])
+{+ int fd, ctl, i;
+ char buf[256];
+ long n;
+
+ if(argc < 2)
+ sysfatal("usage: tread timeout");+
+ atnotify(alarmed, 1);
+
+ fd = open("/dev/cons", ORDWR);+ if(fd < 0)
+ sysfatal("open cons: %r");+ ctl = open("/dev/consctl", OWRITE);+ if(ctl < 0)
+ sysfatal("open consctl: %r");+
+ write(ctl, "rawon", 5);
+ alarm(atoi(argv[1])*1000);
+
+ readline(fd, buf, sizeof(buf));
+ close(ctl);
+ close(fd);
+ print("%s", buf);+ exits(nil);
+}
--- a/sys/src/9/port/bootfs.proto
+++ b/sys/src/9/port/bootfs.proto
@@ -30,6 +30,7 @@
seq
srv
test
+ tread 555 sys sys ../boot/tread
unmount
usb
usbd
--- a/sys/src/9/port/mkbootfs
+++ b/sys/src/9/port/mkbootfs
@@ -33,6 +33,11 @@
rm boot.bz2
}
+@{cd ../boot+ . /$cputype/mkfile
+ mk -f bootmkfile tread
+}
+
bootraw
bootbz2
rootbz2
--
⑨