9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Plan9 as Unix client?
@ 2002-09-30  9:28 John E. Barham
  0 siblings, 0 replies; 3+ messages in thread
From: John E. Barham @ 2002-09-30  9:28 UTC (permalink / raw)
  To: 9fans

Hi folks,

After a lengthy hiatus I'd like to get back to playing w/ Plan9.  So far the
install from CD has been very smooth.

I have to remotely admin a FreeBSD server.  So far I've been using Tera Term
on Windows (i.e., an ssh enabled terminal emulator) but it's a pain doing
any serious file editing and I don't care to use either vi or emacs.

I'm assuming that Plan9's ssh client is as good as anything else, but how
viable would running acme w/ ftpfs connected to my server be as a remote
editor?

    John


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] Plan9 as Unix client?
@ 2002-09-30 18:22 Russ Cox
  0 siblings, 0 replies; 3+ messages in thread
From: Russ Cox @ 2002-09-30 18:22 UTC (permalink / raw)
  To: 9fans

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%



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] Plan9 as Unix client?
@ 2002-09-30  9:37 Fco.J.Ballesteros
  0 siblings, 0 replies; 3+ messages in thread
From: Fco.J.Ballesteros @ 2002-09-30  9:37 UTC (permalink / raw)
  To: 9fans

> I'm assuming that Plan9's ssh client is as good as anything else, but how
> viable would running acme w/ ftpfs connected to my server be as a remote
> editor?

I've done that and it runs nicely; however, I get better behaviour
just using u9fs on the unix machine (IMHO, that's what most of us do).



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-30 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-30  9:28 [9fans] Plan9 as Unix client? John E. Barham
2002-09-30  9:37 Fco.J.Ballesteros
2002-09-30 18:22 Russ Cox

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).