changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: adding experimental rcpu service

changeset 5096: 65abc13ef7a1
parent 5095: 2c3d9125dcdf
child 5097: 7235a8f6c8a5
author: cinap_lenrek@felloff.net
date: Sun, 14 Feb 2016 05:18:33 +0100
files: rc/bin/rconnect rc/bin/rcpu rc/bin/rexport rc/bin/rimport rc/bin/service/tcp17019 sys/lib/dist/ndb/common
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.1new file mode 100755
     1.2--- /dev/null
     1.3+++ b/rc/bin/rconnect
     1.4@@ -0,0 +1,84 @@
     1.5+#!/bin/rc
     1.6+rfork e
     1.7+
     1.8+argv0=$0
     1.9+fn usage {
    1.10+	echo 'usage:' $argv0 '[-p] [-u user] [-k keyspec] host remotescript localcommand ...' >[1=2]
    1.11+	exit 'usage'
    1.12+}
    1.13+
    1.14+fn pvar {
    1.15+	while(! ~ $#* 0){
    1.16+		~ $#$1 0 || path=/dev/null builtin whatis $1
    1.17+		shift
    1.18+	}
    1.19+}
    1.20+
    1.21+filter=()
    1.22+keyspec=()
    1.23+while(~ $1 -*){
    1.24+	switch($1){
    1.25+	case -p; filter=aan
    1.26+	case *
    1.27+		~ $#* 1 && usage
    1.28+		switch($1){
    1.29+		case -k; keyspec=($keyspec $2)
    1.30+		case -u; keyspec=($keyspec `{user=$2 pvar user})
    1.31+		case *; usage
    1.32+		}
    1.33+		shift
    1.34+	}
    1.35+	shift
    1.36+}
    1.37+
    1.38+~ $#* 0 1 2 && usage
    1.39+
    1.40+host=$1
    1.41+shift
    1.42+
    1.43+fn sendscript {
    1.44+	echo -n $host >/proc/$pid/args
    1.45+	cat $1 >/env/v; wc -c </env/v; cat /env/v; rm /env/v
    1.46+	shift
    1.47+	$*
    1.48+}
    1.49+
    1.50+if(~ $filter aan){
    1.51+	fn aanserver {
    1.52+		~ $#netdir 1 || netdir=/net/tcp/clone
    1.53+		netdir=`{basename -d $netdir} || exit
    1.54+		<>$netdir/clone {
    1.55+			netdir=$netdir/`{read} || exit
    1.56+			>[3] $netdir/ctl {
    1.57+				echo -n 'announce *!0' >[1=3]
    1.58+				echo `{cat $netdir/local} || exit
    1.59+				bind '#|' /mnt/aan || exit
    1.60+				exec aan $netdir <>/mnt/aan/data1 >[1=0] >[2]/dev/null &
    1.61+			}
    1.62+		}
    1.63+		<>/mnt/aan/data >[1=0] >[2]/dev/null {
    1.64+			rfork n
    1.65+			fn server {
    1.66+				echo -n aanserver $netdir >/proc/$pid/args
    1.67+				. <{n=`{read} && ! ~ $#n 0 && read -c $n} >[2=1]
    1.68+			}
    1.69+			rm -f /env/^'fn#aanserver'
    1.70+			exec tlssrv -A /bin/rc -c server
    1.71+			exit
    1.72+		}
    1.73+	}
    1.74+	fn aanclient {
    1.75+		host=`{echo $host | sed 's/(.*)!([^!]+)$/\1/'}^!^`{read | sed 's/(.*)!([^!]+)$/\2/'} || exit
    1.76+		tlsclient -a -o <>{rfork s; aan -c $host >[1=0]} /bin/rc -c 'sendscript $*' $*
    1.77+	}
    1.78+	exec $argv0 -k $"keyspec $host <{builtin whatis aanserver; echo aanserver} aanclient $*
    1.79+	exit
    1.80+}
    1.81+
    1.82+switch($host){
    1.83+case *!*!*;
    1.84+case *!*; host=$host!rcpu
    1.85+case *; host=net!$host!rcpu
    1.86+}
    1.87+
    1.88+exec tlsclient -ak $"keyspec $host /bin/rc -c 'sendscript $*' $*
     2.1new file mode 100755
     2.2--- /dev/null
     2.3+++ b/rc/bin/rcpu
     2.4@@ -0,0 +1,83 @@
     2.5+#!/bin/rc
     2.6+rfork e
     2.7+
     2.8+argv0=$0
     2.9+fn usage {
    2.10+	echo 'usage:' $argv0 '[-p] [-h host] [-u user] [-k keypattern] [-P patternfile] [-c cmd arg ...]' >[1=2]
    2.11+	exit 'usage'
    2.12+}
    2.13+
    2.14+fn server {
    2.15+	mount -nc /fd/0 /mnt/term || exit
    2.16+	bind -q /mnt/term/dev/cons /dev/cons
    2.17+	</mnt/term/fd/10 >/mnt/term/fd/11 >[2]/mnt/term/fd/12 {
    2.18+		~ $#dir 0 || cd $"dir || echo 'can''t change directory: '^$"dir >[1=2]
    2.19+		switch($#cmd){
    2.20+		case 0;	cmd=(rc -li)
    2.21+		case 1; cmd=(rc -lc $cmd)
    2.22+		case *; cmd=(rc -lc '$*' $cmd)
    2.23+		}
    2.24+	 	rm -f /env/^(cmd dir 'fn#server')
    2.25+	 	service=cpu exec $cmd
    2.26+	} &
    2.27+	if(test -d /mnt/term/mnt/cpunote) {
    2.28+		rfork e
    2.29+		mainproc=$apid
    2.30+		exec cat </mnt/term/mnt/cpunote/data >/proc/$mainproc/notepg &
    2.31+		noteproc=$apid
    2.32+		wait $mainproc
    2.33+		echo -n $status >/mnt/term/env/rstatus >[2]/dev/null
    2.34+		echo -n kill >/proc/$noteproc/note
    2.35+	}
    2.36+}
    2.37+
    2.38+fn client {
    2.39+	echo -n >/env/rstatus
    2.40+	rfork n
    2.41+	bind '#|' /mnt/cpunote || exit
    2.42+	</fd/0 exec $exportfs -r / &
    2.43+	</dev/null >/mnt/cpunote/data1 {
    2.44+		fn sigkill { echo -n kill >/mnt/cpunote/data1 }
    2.45+		fn sighup { echo -n hangup >/mnt/cpunote/data1 }
    2.46+		fn sigint { status=interrupted }
    2.47+		wait
    2.48+		while(~ $status interrupted) {
    2.49+			echo -n interrupt
    2.50+			wait
    2.51+		}
    2.52+		status=`{cat /env/rstatus}
    2.53+		exit $"status
    2.54+	}
    2.55+}
    2.56+
    2.57+cmd=()
    2.58+host='$cpu'
    2.59+exportfs=/bin/exportfs
    2.60+connect=/bin/rconnect
    2.61+
    2.62+while(~ $1 -*){
    2.63+	switch($1){
    2.64+	case -p; connect=($connect $1)
    2.65+	case *
    2.66+		~ $#* 1 && usage
    2.67+		switch($1){
    2.68+		case -P; exportfs=($exportfs $1 $2)
    2.69+		case -[uk]; connect=($connect $1 $2)
    2.70+		case -h; host=$2
    2.71+		case -c; cmd=$*(2-); *=()
    2.72+		case *; usage
    2.73+		}
    2.74+		shift
    2.75+	}
    2.76+	shift
    2.77+}
    2.78+~ $#* 0 || usage
    2.79+
    2.80+fn pvar {
    2.81+	while(! ~ $#* 0){
    2.82+		~ $#$1 0 || path=/dev/null builtin whatis $1
    2.83+		shift
    2.84+	}
    2.85+}
    2.86+
    2.87+exec $connect $host <{dir=`{pwd} pvar dir cmd; builtin whatis server; echo server} client <[10=0] >[11=1] >[12=2]
     3.1new file mode 100755
     3.2--- /dev/null
     3.3+++ b/rc/bin/rexport
     3.4@@ -0,0 +1,57 @@
     3.5+#!/bin/rc
     3.6+rfork e
     3.7+
     3.8+argv0=$0
     3.9+fn usage {
    3.10+	echo 'usage:' $argv0 '[options] [-s remotesrv] [-m remotemtpt] tree host [remotecmd [args ...]]' >[1=2]
    3.11+	exit 'usage'
    3.12+}
    3.13+
    3.14+fn domount {
    3.15+	if(~ $#sname 1){
    3.16+		rm -f /srv/$sname
    3.17+		echo -n 0 >/srv/$sname
    3.18+	}
    3.19+	~ $#mtpt 0 || mount -n $mopt /fd/0 $mtpt || exit
    3.20+	~ $#cmd 0 || service=import exec $cmd </dev/null >/dev/null >[2=1]
    3.21+}
    3.22+
    3.23+sname=()
    3.24+mopt=()
    3.25+mtpt=()
    3.26+exportfs=/bin/exportfs
    3.27+connect=/bin/rconnect
    3.28+
    3.29+while(~ $1 -*){
    3.30+	switch($1){
    3.31+	case -p; connect=($connect $1)
    3.32+	case -[abcCnq]*; mopt=($mopt $1)
    3.33+	case *
    3.34+		~ $#* 1 && usage
    3.35+		switch($1){
    3.36+		case -P; exportfs=($exportfs $1 $2)
    3.37+		case -[uk]; connect=($connect $1 $2)
    3.38+		case -s; sname=`{basename $2}
    3.39+		case -m; mtpt=$2
    3.40+		case *; usage
    3.41+		}
    3.42+		shift
    3.43+	}
    3.44+	shift
    3.45+}
    3.46+~ $#* 0 1 && usage
    3.47+
    3.48+exportfs=($exportfs -r $1)
    3.49+shift
    3.50+host=$1
    3.51+shift
    3.52+cmd=$*
    3.53+
    3.54+fn pvar {
    3.55+	while(! ~ $#* 0){
    3.56+		~ $#$1 0 || path=/dev/null builtin whatis $1
    3.57+		shift
    3.58+	}
    3.59+}
    3.60+
    3.61+exec $connect $host <{pvar sname mtpt mopt cmd; builtin whatis domount; echo domount} exec $exportfs
     4.1new file mode 100755
     4.2--- /dev/null
     4.3+++ b/rc/bin/rimport
     4.4@@ -0,0 +1,52 @@
     4.5+#!/bin/rc
     4.6+rfork e
     4.7+
     4.8+argv0=$0
     4.9+fn usage {
    4.10+	echo 'usage:' $argv0 '[options] host tree [mountpoint]' >[1=2]
    4.11+	exit 'usage'
    4.12+}
    4.13+
    4.14+fn domount {
    4.15+	if(~ $#sname 1){
    4.16+		rm -f /srv/$sname
    4.17+		echo -n 0 >/srv/$sname
    4.18+	}
    4.19+	~ $#mtpt 0 || mount -n $mopt /fd/0 $mtpt
    4.20+}
    4.21+
    4.22+tree=()
    4.23+mopt=()
    4.24+mtpt=()
    4.25+sname=()
    4.26+exportfs=/bin/exportfs
    4.27+connect=/bin/rconnect
    4.28+
    4.29+while(~ $1 -*){
    4.30+	switch($1){
    4.31+	case -p; connect=($connect $1)
    4.32+	case -[abcCnq]*; mopt=($mopt $1)
    4.33+	case *
    4.34+		~ $#* 1 && usage
    4.35+		switch($1){
    4.36+		case -[uk]; connect=($connect $1 $2)
    4.37+		case -s; sname=`{basename $2}
    4.38+		case *; usage
    4.39+		}
    4.40+		shift
    4.41+	}
    4.42+	shift
    4.43+}
    4.44+switch($#*){
    4.45+case 2 3; tree=$2; mtpt=$$#*
    4.46+case *; usage
    4.47+}
    4.48+
    4.49+fn pvar {
    4.50+	while(! ~ $#* 0){
    4.51+		~ $#$1 0 || path=/dev/null builtin whatis $1
    4.52+		shift
    4.53+	}
    4.54+}
    4.55+
    4.56+exec $connect $1 <{pvar tree; echo exec $exportfs -r '$tree'} domount
     5.1new file mode 100755
     5.2--- /dev/null
     5.3+++ b/rc/bin/service/tcp17019
     5.4@@ -0,0 +1,8 @@
     5.5+#!/bin/rc
     5.6+netdir=$3
     5.7+remote=$2!`{cat $3/remote}
     5.8+fn server {
     5.9+	echo -n $netdir $remote >/proc/$pid/args
    5.10+	. <{n=`{read} && ! ~ $#n 0 && read -c $n} >[2=1]
    5.11+}
    5.12+exec tlssrv -a /bin/rc -c server
     6.1--- a/sys/lib/dist/ndb/common
     6.2+++ b/sys/lib/dist/ndb/common
     6.3@@ -284,6 +284,7 @@ tcp=exportfs port=17007
     6.4 tcp=rexexec port=17009
     6.5 tcp=ncpu port=17010
     6.6 tcp=cpu port=17013
     6.7+tcp=rcpu port=17019
     6.8 tcp=glenglenda1 port=17020
     6.9 tcp=glenglenda2 port=17021
    6.10 tcp=glenglenda3 port=17022