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