Add /sys/src/9/boot/tread, a tool to read a line with a timeout.
While here, remove boot(8) references to pcload.
This commit is contained in:
parent
6ef6d247bc
commit
b261a0c31b
7 changed files with 88 additions and 25 deletions
|
@ -16,3 +16,7 @@ $BOOTFILES: $BOOTDIR/boot.h
|
|||
|
||||
%.$O: $BOOTDIR/%.c
|
||||
$CC -I$BOOTDIR $CFLAGS $BOOTDIR/$stem.c
|
||||
|
||||
tread: tread.c
|
||||
$CC tread.c
|
||||
$LD -o tread tread.8
|
||||
|
|
|
@ -67,22 +67,17 @@ fn readmethod{
|
|||
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)
|
||||
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 readmethod{
|
|||
|
||||
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 @@ fn main{
|
|||
$mp($connect)
|
||||
|
||||
must mount -c /srv/boot /root
|
||||
if(~ $pcload 1){
|
||||
echo reboot /root/$kern >/dev/reboot
|
||||
fatal kernel load failed: $kern
|
||||
}
|
||||
|
||||
swapproc
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ fn confmount{
|
|||
}
|
||||
|
||||
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
|
||||
|
|
7
sys/src/9/boot/local.rc
Executable file → Normal file
7
sys/src/9/boot/local.rc
Executable file → Normal file
|
@ -5,13 +5,6 @@ fn configlocal{
|
|||
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
|
||||
}
|
||||
|
||||
|
|
73
sys/src/9/boot/tread.c
Normal file
73
sys/src/9/boot/tread.c
Normal file
|
@ -0,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);
|
||||
}
|
|
@ -30,6 +30,7 @@ $cputype
|
|||
seq
|
||||
srv
|
||||
test
|
||||
tread 555 sys sys ../boot/tread
|
||||
unmount
|
||||
usb
|
||||
usbd
|
||||
|
|
|
@ -33,6 +33,11 @@ fn rootbz2 {
|
|||
rm boot.bz2
|
||||
}
|
||||
|
||||
@{cd ../boot
|
||||
. /$cputype/mkfile
|
||||
mk -f bootmkfile tread
|
||||
}
|
||||
|
||||
bootraw
|
||||
bootbz2
|
||||
rootbz2
|
||||
|
|
Loading…
Reference in a new issue