mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
import: add -x flag
This commit is contained in:
parent
3d52c7487f
commit
351f474b11
2 changed files with 41 additions and 26 deletions
|
@ -4,7 +4,7 @@ import \- import 9P resources from another system
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B import
|
.B import
|
||||||
[
|
[
|
||||||
.B -df
|
.B -dfx
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
.B -n
|
.B -n
|
||||||
|
@ -67,6 +67,12 @@ The
|
||||||
option keeps
|
option keeps
|
||||||
.I import
|
.I import
|
||||||
from forking itself into the background, also useful for debugging.
|
from forking itself into the background, also useful for debugging.
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B -x
|
||||||
|
option reverses the roles of the two machines,
|
||||||
|
exporting the service to, instead of importing it from,
|
||||||
|
the remote system.
|
||||||
.SH EXAMPLE
|
.SH EXAMPLE
|
||||||
Suppose you run
|
Suppose you run
|
||||||
.B sam
|
.B sam
|
||||||
|
|
|
@ -7,19 +7,20 @@
|
||||||
int debug;
|
int debug;
|
||||||
int dfd;
|
int dfd;
|
||||||
int srvfd;
|
int srvfd;
|
||||||
int netfd;
|
int netfd[2];
|
||||||
int srv_to_net[2];
|
int srv_to_net[2];
|
||||||
int net_to_srv[2];
|
int net_to_srv[2];
|
||||||
char *srv;
|
char *srv;
|
||||||
char *addr;
|
char *addr;
|
||||||
char *ns;
|
char *ns;
|
||||||
|
int export;
|
||||||
|
|
||||||
void shuffle(void *arg);
|
void shuffle(void *arg);
|
||||||
int post(char *srv);
|
int post(char *srv);
|
||||||
void remoteside(char *ns, char *srv);
|
void remoteside(void*);
|
||||||
int call(char *rsys, char *ns, char *srv);
|
int call(char *rsys, char *ns, char *srv);
|
||||||
void* emalloc(int size);
|
void* emalloc(int size);
|
||||||
void runproc(void *arg);
|
void localside(void*);
|
||||||
|
|
||||||
char *REXEXEC = "ssh";
|
char *REXEXEC = "ssh";
|
||||||
char *prog = "import";
|
char *prog = "import";
|
||||||
|
@ -55,6 +56,7 @@ threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int dofork;
|
int dofork;
|
||||||
int rem;
|
int rem;
|
||||||
|
void (*fn)(void*);
|
||||||
|
|
||||||
dofork = 1;
|
dofork = 1;
|
||||||
rem = 0;
|
rem = 0;
|
||||||
|
@ -80,6 +82,9 @@ threadmain(int argc, char *argv[])
|
||||||
case 'R':
|
case 'R':
|
||||||
rem = 1;
|
rem = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
export = 1;
|
||||||
|
break;
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(debug){
|
if(debug){
|
||||||
|
@ -94,39 +99,43 @@ threadmain(int argc, char *argv[])
|
||||||
fmtinstall('F', fcallfmt);
|
fmtinstall('F', fcallfmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is this the remote side? */
|
|
||||||
if(rem){
|
|
||||||
if(srv == nil)
|
|
||||||
fatal("-R requires -s");
|
|
||||||
remoteside(ns, srv);
|
|
||||||
threadexitsall(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(rem){
|
||||||
|
netfd[0] = 0;
|
||||||
|
netfd[1] = 1;
|
||||||
|
write(1, "OK", 2);
|
||||||
|
}else{
|
||||||
if(argc != 1)
|
if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
addr = argv[0];
|
addr = argv[0];
|
||||||
|
/* connect to remote service */
|
||||||
|
netfd[0] = netfd[1] = call(addr, ns, srv);
|
||||||
|
}
|
||||||
|
|
||||||
if(dofork)
|
fn = localside;
|
||||||
proccreate(runproc, nil, Stack);
|
if(rem+export == 1)
|
||||||
|
fn = remoteside;
|
||||||
|
|
||||||
|
if(rem || !dofork)
|
||||||
|
fn(nil);
|
||||||
else
|
else
|
||||||
runproc(nil);
|
proccreate(fn, nil, Stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
runproc(void *arg)
|
localside(void *arg)
|
||||||
{
|
{
|
||||||
USED(arg);
|
USED(arg);
|
||||||
|
|
||||||
/* start a loal service and connect to remote service */
|
/* start a loal service */
|
||||||
srvfd = post(srv);
|
srvfd = post(srv);
|
||||||
netfd = call(addr, ns, srv);
|
|
||||||
|
|
||||||
/* threads to shuffle messages each way */
|
/* threads to shuffle messages each way */
|
||||||
srv_to_net[0] = srvfd;
|
srv_to_net[0] = srvfd;
|
||||||
srv_to_net[1] = netfd;
|
srv_to_net[1] = netfd[1];
|
||||||
proccreate(shuffle, srv_to_net, Stack);
|
proccreate(shuffle, srv_to_net, Stack);
|
||||||
net_to_srv[0] = netfd;
|
net_to_srv[0] = netfd[0];
|
||||||
net_to_srv[1] = srvfd;
|
net_to_srv[1] = srvfd;
|
||||||
shuffle(net_to_srv);
|
shuffle(net_to_srv);
|
||||||
}
|
}
|
||||||
|
@ -172,6 +181,8 @@ call(char *rsys, char *ns, char *srv)
|
||||||
}
|
}
|
||||||
av[ac++] = "-s";
|
av[ac++] = "-s";
|
||||||
av[ac++] = srv;
|
av[ac++] = srv;
|
||||||
|
if(export)
|
||||||
|
av[ac++] = "-x";
|
||||||
av[ac] = 0;
|
av[ac] = 0;
|
||||||
|
|
||||||
if(debug){
|
if(debug){
|
||||||
|
@ -254,7 +265,7 @@ shuffle(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
remoteside(char *ns, char *srv)
|
remoteside(void *v)
|
||||||
{
|
{
|
||||||
int srv_to_net[2];
|
int srv_to_net[2];
|
||||||
int net_to_srv[2];
|
int net_to_srv[2];
|
||||||
|
@ -277,13 +288,11 @@ remoteside(char *ns, char *srv)
|
||||||
fprint(dfd, "remoteside dial %s succeeded\n", addr);
|
fprint(dfd, "remoteside dial %s succeeded\n", addr);
|
||||||
fcntl(srvfd, F_SETFL, FD_CLOEXEC);
|
fcntl(srvfd, F_SETFL, FD_CLOEXEC);
|
||||||
|
|
||||||
write(1, "OK", 2);
|
|
||||||
|
|
||||||
/* threads to shuffle messages each way */
|
/* threads to shuffle messages each way */
|
||||||
srv_to_net[0] = srvfd;
|
srv_to_net[0] = srvfd;
|
||||||
srv_to_net[1] = 1;
|
srv_to_net[1] = netfd[1];
|
||||||
proccreate(shuffle, srv_to_net, Stack);
|
proccreate(shuffle, srv_to_net, Stack);
|
||||||
net_to_srv[0] = 0;
|
net_to_srv[0] = netfd[0];
|
||||||
net_to_srv[1] = srvfd;
|
net_to_srv[1] = srvfd;
|
||||||
shuffle(net_to_srv);
|
shuffle(net_to_srv);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue