From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Plan9 as Unix client?
Date: Mon, 30 Sep 2002 14:22:25 -0400 [thread overview]
Message-ID: <555da4fc41a3a74cef0fd23beb4b5d42@plan9.bell-labs.com> (raw)
I use the below program, srvprog.c, to start u9fs via ssh.
It works quite a bit better than ftpfs, and of course it's
encrypted.
g% cat /usr/rsc/bin/rc/9fs
#!/bin/rc
switch($1){
case ny
srvprog 'ssh -Rmp ny.lcs.mit.edu ./bin/sh/u9fs.openbsd' ny /n/ny
...
case *
exec /rc/bin/9fs $*
}
exit ''
g% ssh ny.lcs.mit.edu cat bin/sh/u9fs.openbsd
#!/bin/sh
/home/ny3/rsc/bin/386/openbsd/u9fs -na none -u rsc -l /home/ny3/rsc/tmp/u9fs.log
g% cat srvprog.c
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <auth.h>
#include <fcall.h>
Fcall hdr;
char *dest;
int mountflag = MREPL;
void error(char *);
void rpc(int, int);
void post(char*, int);
void mountfs(char*, int);
void
usage(void)
{
fprint(2, "usage: srvprog [-abcCmr] 'command args' srvname [mtpt]\n");
exits("usage");
}
void
ignore(void *a, char *c)
{
USED(a);
if(strcmp(c, "alarm") == 0){
fprint(2, "srv: timeout establishing connection\n");
exits("timeout");
}
noted(NDFLT);
}
int
connectcmd(char *cmd)
{
int p[2];
if(pipe(p) < 0)
return -1;
switch(fork()){
case -1:
fprint(2, "fork failed: %r\n");
_exits("exec");
case 0:
dup(p[0], 0);
dup(p[0], 1);
close(p[1]);
execl("/bin/rc", "rc", "-c", cmd, nil);
fprint(2, "exec failed: %r\n");
_exits("exec");
default:
close(p[0]);
return p[1];
}
}
void
main(int argc, char *argv[])
{
int fd, n;
char srv[64], mtpt0[64], *mtpt;
char err[ERRMAX], buf[32];
int domount, reallymount, try;
notify(ignore);
alarm(30000);
domount = 0;
reallymount = 0;
mtpt = nil;
ARGBEGIN{
case 'a':
mountflag |= MAFTER;
domount = 1;
reallymount = 1;
break;
case 'b':
mountflag |= MBEFORE;
domount = 1;
reallymount = 1;
break;
case 'c':
mountflag |= MCREATE;
domount = 1;
reallymount = 1;
break;
case 'C':
mountflag |= MCACHE;
domount = 1;
reallymount = 1;
break;
case 'm':
domount = 1;
reallymount = 1;
break;
case 'q':
domount = 1;
reallymount = 0;
break;
default:
usage();
break;
}ARGEND
if((mountflag&MAFTER)&&(mountflag&MBEFORE))
usage();
switch(argc){
case 1: /* calculate srv and mtpt from address */
usage();
case 2: /* calculate mtpt from srv */
snprint(srv, sizeof(srv), "/srv/%.28s", argv[1]);
snprint(mtpt0, sizeof(mtpt0), "/n/%.28s", argv[1]);
mtpt = mtpt0;
break;
case 3: /* srv and mtpt given */
domount = 1;
reallymount = 1;
snprint(srv, sizeof(srv), "/srv/%.28s", argv[1]);
mtpt = argv[2];
break;
default:
usage();
}
try = 0;
Again:
try++;
if(access(srv, 0) == 0){
if(domount){
fd = open(srv, ORDWR);
if(fd >= 0)
goto Mount;
remove(srv);
}
else{
fprint(2, "srv: %s already exists\n", srv);
exits(0);
}
}
dest = argv[0];
alarm(10000);
fd = connectcmd(dest);
alarm(0);
if(fd < 0)
sysfatal("srvprog: connectcmd %s: %r", dest);
fprint(2, "version...");
buf[0] = '\0';
n = fversion(fd, 0, buf, sizeof buf);
if(n < 0){
fprint(2, "srv %s: fversion failed: %r\n", dest);
exits("version");
}
post(srv, fd);
Mount:
if(domount == 0 || reallymount == 0)
exits(0);
if(amount(fd, mtpt, mountflag, "") < 0){
err[0] = 0;
rerrstr(err, sizeof err);
if(strstr(err, "hungup") || strstr(err, "timed out")){
remove(srv);
if(try == 1)
goto Again;
}
fprint(2, "srv %s: mount failed: %s\n", dest, err);
exits("mount");
}
exits(0);
}
void
post(char *srv, int fd)
{
int f;
char buf[128];
fprint(2, "post...\n");
f = create(srv, OWRITE, 0666);
if(f < 0){
sprint(buf, "create(%s)", srv);
error(buf);
}
sprint(buf, "%d", fd);
if(write(f, buf, strlen(buf)) != strlen(buf))
error("write");
}
void
error(char *s)
{
fprint(2, "srv %s: %s: %r\n", dest, s);
exits("srv: error");
}
g%
next reply other threads:[~2002-09-30 18:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-30 18:22 Russ Cox [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-09-30 9:37 Fco.J.Ballesteros
2002-09-30 9:28 John E. Barham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555da4fc41a3a74cef0fd23beb4b5d42@plan9.bell-labs.com \
--to=rsc@plan9.bell-labs.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).