blob: 54f670c674ef674c365a35502e09e2b175d0f2e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/bin/rc
rfork e
argv0=$0
fn usage {
echo 'usage:' $argv0 '[-u user] [-k keypattern] [-P patternfile] [-p] [-t timeout] [-h host] [-c cmd arg ...]' >[1=2]
exit 'usage'
}
fn server {
mount -nc /fd/0 /mnt/term || exit
bind -q /mnt/term/dev/cons /dev/cons
</mnt/term/fd/10 >/mnt/term/fd/11 >[2]/mnt/term/fd/12 {
~ $#dir 0 || cd $"dir || echo 'can''t change directory: '^$"dir >[1=2]
switch($#cmd){
case 0; cmd=(rc -li)
case 1; cmd=(rc -lc $cmd)
case *; cmd=(rc -lc '$*' $cmd)
}
rm -f /env/^(cmd dir 'fn#server')
service=cpu exec $cmd
} &
if(test -d /mnt/term/mnt/cpunote) {
rfork e
mainproc=$apid
{cat; echo -n hangup} </mnt/term/mnt/cpunote/data >/proc/$mainproc/notepg &
noteproc=$apid
wait $mainproc
echo -n $status >/mnt/term/env/rstatus >[2]/dev/null
echo -n hangup >/proc/$noteproc/notepg
}
}
fn client {
echo -n >/env/rstatus
rfork n
bind '#|' /mnt/cpunote || exit
</fd/0 exec $exportfs -r / &
</dev/null >/mnt/cpunote/data1 {
fn sigkill { echo -n kill >/mnt/cpunote/data1 }
fn sighup { echo -n hangup >/mnt/cpunote/data1 }
fn sigint { status=interrupted }
wait
while(~ $status interrupted) {
echo -n interrupt
wait
}
status=`{cat /env/rstatus}
exit $"status
}
}
cmd=()
host='$cpu'
if(~ $#cpu 1) host=$cpu
exportfs=/bin/exportfs
connect=/bin/rconnect
while(~ $1 -*){
switch($1){
case -p; connect=($connect $1)
case *
~ $#* 1 && usage
switch($1){
case -P; exportfs=($exportfs $1 $2)
case -[ukt]; connect=($connect $1 $2)
case -h; host=$2
case -c; cmd=$*(2-); *=()
case *; usage
}
shift
}
shift
}
~ $#* 0 || usage
fn pvar {
while(! ~ $#* 0){
~ $#$1 0 && echo $1'=()' ||
path=/dev/null builtin whatis $1
shift
}
}
>/env/rscript {
dir=`{pwd} pvar dir cmd
builtin whatis server
echo server
}
exec $connect $host /env/rscript client <[10=0] >[11=1] >[12=2]
|