changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/rexport

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 '[options] [-s remotesrv] [-m remotemtpt] tree host [remotecmd [args ...]]' >[1=2]
7  exit 'usage'
8 }
9 
10 fn domount {
11  if(~ $#sname 1){
12  rm -f /srv/$sname
13  echo -n 0 >/srv/$sname
14  }
15  ~ $#mtpt 0 || mount -n $mopt /fd/0 $mtpt || exit
16  ~ $#cmd 0 || service=import exec $cmd </dev/null >/dev/null >[2=1]
17 }
18 
19 sname=()
20 mopt=()
21 mtpt=()
22 exportfs=/bin/exportfs
23 connect=/bin/rconnect
24 
25 while(~ $1 -*){
26  switch($1){
27  case -p; connect=($connect $1)
28  case -[abcCnq]*; mopt=($mopt $1)
29  case *
30  ~ $#* 1 && usage
31  switch($1){
32  case -P; exportfs=($exportfs $1 $2)
33  case -[uk]; connect=($connect $1 $2)
34  case -s; sname=`{basename $2}
35  case -m; mtpt=$2
36  case *; usage
37  }
38  shift
39  }
40  shift
41 }
42 ~ $#* 0 1 && usage
43 
44 exportfs=($exportfs -r $1)
45 shift
46 host=$1
47 shift
48 cmd=$*
49 
50 fn pvar {
51  while(! ~ $#* 0){
52  ~ $#$1 0 || path=/dev/null builtin whatis $1
53  shift
54  }
55 }
56 
57 exec $connect $host <{pvar sname mtpt mopt cmd; builtin whatis domount; echo domount} exec $exportfs