changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/rcpu

changeset 5096: 65abc13ef7a1
child: c392f6b2122c
author: cinap_lenrek@felloff.net
date: Sun, 14 Feb 2016 05:18:33 +0100
permissions: -rwxr-xr-x
description: adding experimental rcpu service

this is a reimplementation of cpu and import utilities in rc using a tlsclient
and tlssrv as the encryption and authentication layers. there is only one new
service, which after authentication and encryption setup accepts an arbitrary
rc script over the network and executes it with the standard filedescriptors
redirected to the conversaion (this is *after* authentication and in the
context of the authorized user).

the new rcpu program has a few improvements over cpu(1):

- doesnt mangle program arguments
- the remote process will get the clients standard file descriptors, so error
and output are separated and you can consume the clients input from the
remote side :-)
- forwards error status of remote process

theres no backwards mode for rimport, but a new program called rexport
for the same purpose.

all these services use exportfs without the bolted on initial handshake,
so the hope is to clean up exportfs in the future and remove all the ugly
crap in there.
1 #!/bin/rc
2 rfork e
3 
4 argv0=$0
5 fn usage {
6  echo 'usage:' $argv0 '[-p] [-h host] [-u user] [-k keypattern] [-P patternfile] [-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  exec cat </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 kill >/proc/$noteproc/note
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 exportfs=/bin/exportfs
56 connect=/bin/rconnect
57 
58 while(~ $1 -*){
59  switch($1){
60  case -p; connect=($connect $1)
61  case *
62  ~ $#* 1 && usage
63  switch($1){
64  case -P; exportfs=($exportfs $1 $2)
65  case -[uk]; connect=($connect $1 $2)
66  case -h; host=$2
67  case -c; cmd=$*(2-); *=()
68  case *; usage
69  }
70  shift
71  }
72  shift
73 }
74 ~ $#* 0 || usage
75 
76 fn pvar {
77  while(! ~ $#* 0){
78  ~ $#$1 0 || path=/dev/null builtin whatis $1
79  shift
80  }
81 }
82 
83 exec $connect $host <{dir=`{pwd} pvar dir cmd; builtin whatis server; echo server} client <[10=0] >[11=1] >[12=2]